<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form
            v-if="tabsKeys != 7 && tabsKeys != 2"
            size="small"
            :model="pageData"
            layout="inline"
          >
            <CorporateSectorCascader
              :configCascader="configCascader3"
              @changeCascader="changeCascader3"
            />
            <a-form-item label="仓库" label-col-flex="70px">
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '200px' }"
                v-model="pageData.b"
                allow-clear
                @change="whChange()"
              >
                <a-option v-for="item in shWhList3" :value="item.id">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item label="领料单号" label-col-flex="70px">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.plan_material_code"
              />
            </a-form-item>
            <a-form-item label="出库单号" label-col-flex="70px">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.out_stock_number"
              />
            </a-form-item>

            <a-form-item label="纱牌" label-col-flex="70px">
              <a-input
                allow-clear
                :style="{ width: '224px' }"
                class="bacClass"
                v-model="pageData.yarnBrand"
              />
            </a-form-item>
            <a-form-item label="纱批" label-col-flex="70px">
              <a-input
                allow-clear
                :style="{ width: '224px' }"
                class="bacClass"
                v-model="pageData.productionBatch"
              />
            </a-form-item>
            <a-form-item label="等级" label-col-flex="70px">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.level"
              />
            </a-form-item>
            <a-form-item
              label="单据类型"
              v-if="tabsKeys == 3 || tabsKeys == 4"
              label-col-flex="70px"
            >
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '200px' }"
                v-model="pageData.orderType"
                allow-clear
              >
                <!-- <a-option :value="0">普通调拨</a-option> -->
                <a-option :value="1">加工出库单</a-option>
                <a-option :value="2">加工领料单</a-option>
                <a-option :value="3">加工收货单</a-option>
                <a-option :value="4">纱线转让单</a-option>
                <a-option :value="5">采购退货单</a-option>
              </a-select>
            </a-form-item>

            <a-form-item label="审核状态" v-if="tabsKeys == 1" label-col-flex="70px">
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '200px' }"
                v-model="pageData.auditState"
                allow-clear
              >
                <a-option :value="0">未审核</a-option>
                <a-option :value="1">已审核</a-option>
                <a-option :value="2">全部</a-option>
              </a-select>
            </a-form-item>
            <a-form-item label="出库类型" label-col-flex="70px">
                  <a-select
                    popup-container="html"
                    class="bacClass"
                    style="width:210px"
                    v-model="pageData.outStockTypes"
                    allow-clear
                    multiple
                    :max-tag-count="1"
                    @focus="getOutStock"
                  >
                    <a-option v-for="item in pageData.outStockList" :value="item" :key="item">
                      {{ item }}
                    </a-option>
                  </a-select>
                </a-form-item>
            <a-form-item label="日期" label-col-flex="70px">
              <a-range-picker
                popup-container="html"
                :style="{ width: '250px' }"
                class="bacClass"
                @clear="onClear"
                allow-clear
                v-model="pageDataLl.dateList1"
              />
            </a-form-item>
          </a-form>
          <a-form v-else size="small" :model="pageDataLl" layout="inline">
            <a-form-item label="领料单号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageDataLl.lingliaodanhao"
              />
            </a-form-item>
            <a-form-item label="客户名称">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageDataLl.kname"
              />
            </a-form-item>
            <a-form-item label="原料编号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageDataLl.yuanliaobianhao"
              />
            </a-form-item>
            <a-form-item label="原料名称">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageDataLl.yuanliaomingc"
              />
            </a-form-item>

            <a-form-item label="审核状态" label-col-flex="70px" v-show="tabsKeys != 2">
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '200px' }"
                v-model="pageDataLl.auditState"
                allow-clear
              >
                <a-option :value="0">未审核</a-option>
                <a-option :value="1">审核通过</a-option>
                <a-option :value="2">驳回</a-option>
              </a-select>
            </a-form-item>

            <a-form-item label="完结状态" label-col-flex="70px" v-show="tabsKeys == 2">
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '200px' }"
                v-model="pageData.useState"
              >
                <a-option value="-1">全部</a-option>
                <a-option :value="0">未完结</a-option>
                <a-option :value="1">已完结</a-option>
              </a-select>
            </a-form-item>
            <a-form-item label="开单日期">
              <a-range-picker
                popup-container="html"
                :style="{ width: '200px' }"
                class="bacClass"
                style="width: 15rem"
                @clear="onClearLl"
                v-model="pageDataLl.dateList"
              />
            </a-form-item>
          </a-form>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="headerShow"
            @click="headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
      <div style="text-align: end">
        <Toolbar
          v-if="tabsKeys != 2 && tabsKeys != 7"
          class="gesture"
          :items="toolbarList"
          @select="selectHandler"
          @add-db="adddbs"
          @del="delSles"
          @audit="audits"
          @oders="redersOut"
          @addAoutSet="addDbFun"
          @add-ck="addcks"
          @dyBoufei="dyBoufeis"
          @cancelAudit="cancelAudit"
        >
        </Toolbar>
        <Toolbar
          v-else-if="tabsKeys == 2"
          class="gesture"
          :items="[
            '调拨单申请',
            `${permissionStore.hasPermisson('yscck.llddclcx') ? '查询' : ''}`,
            `${permissionStore.hasPermisson('yscck.llddclck') ? '出库' : ''}`,
            '完结',
          ]"
          @select="selectHandler"
          @oders="redersOut"
          @addAoutSet="addDbFun"
          @theEnd="theEnds"
        >
        </Toolbar>
        <Toolbar
          v-else-if="tabsKeys == 7"
          :items="[`查询`, '需求单汇总', `调拨单申请`, `审核`, `反审`, `驳回`, `删除`]"
          @select="selectCx"
          @audit="auditsLlDb"
          @rejected="rejectedsLlDb"
          @del="delsLlDb"
          @counter="countersLlDb"
          @addAoutSet="addDbFuns"
          @xuqiudanhuiz="xqdhzs"
        >
        </Toolbar>
      </div>
      <div class="gang"></div>
    </template>
    <template #pageTabel>
      <a-tabs
        :lazy-load="true"
        :justify="true"
        :default-active-key="tabsKeys"
        @change="tabsChanges"
      >
        <a-tab-pane title="已处理" :key="1">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady"
            @columnResized="onColumnResized"
            @columnMoved="onColumnMoved"
            @columnVisible="onColumnVisible"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableDataList"
            :columnDefs="tc"
            :localeText="localeText1"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet2.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize2"
            @page-size-change="change2"
            style="justify-content: center"
            :page-size="fySelet2.size"
            :current="fySelet2.page"
          />
        </a-tab-pane>
        <a-tab-pane title="领料单审核" :key="7">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReadyLls"
            @columnResized="onColumnResized2"
            @columnMoved="onColumnMoved2"
            @columnVisible="onColumnVisible2"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="LlDataList"
            :columnDefs="tcLls"
            :localeText="localeText1"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySeletLl.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSizeLl"
            @page-size-change="changeLl"
            style="justify-content: center"
            :page-size="fySeletLl.size"
            :current="fySeletLl.page"
          />
        </a-tab-pane>
        <a-tab-pane title="领料单待处理" :key="2">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady2"
            @columnResized="onColumnResized3"
            @columnMoved="onColumnMoved3"
            @columnVisible="onColumnVisible3"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef2"
            class="ag-theme-alpine"
            :rowData="tableDataList2"
            :columnDefs="tc2"
            :localeText="localeText1"
          >
          </AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize"
            @page-size-change="change"
            style="justify-content: center"
            :page-size="fySelet.size"
            :current="fySelet.page"
          />
        </a-tab-pane>
        <a-tab-pane title="调拨出库待处理" :key="3">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady3"
            @columnResized="onColumnResized4"
            @columnMoved="onColumnMoved4"
            @columnVisible="onColumnVisible4"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef3"
            class="ag-theme-alpine"
            :rowData="tableDataList3"
            :columnDefs="tc3"
            :localeText="localeText1"
          >
          </AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet5.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize5"
            @page-size-change="change5"
            style="justify-content: center"
            :page-size="fySelet5.size"
            :current="fySelet5.page"
          />
        </a-tab-pane>
        <a-tab-pane title="调拨出库已处理" :key="4">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady5"
            @columnResized="onColumnResized5"
            @columnMoved="onColumnMoved5"
            @columnVisible="onColumnVisible5"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableDataList5"
            :columnDefs="tc3"
            :localeText="localeText1"
          >
          </AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet4.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize4"
            @page-size-change="change4"
            style="justify-content: center"
            :page-size="fySelet4.size"
            :current="fySelet4.page"
          />
        </a-tab-pane>
        <a-tab-pane title="退库出库单" :key="5">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady6"
            @columnResized="onColumnResized6"
            @columnMoved="onColumnMoved6"
            @columnVisible="onColumnVisible6"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableDataList6"
            :columnDefs="tc6"
            :localeText="localeText1"
          >
          </AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet6.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize6"
            @page-size-change="change6"
            style="justify-content: center"
            :page-size="fySelet6.size"
            :current="fySelet6.page"
          />
        </a-tab-pane>
        <a-tab-pane title="委外出库单" :key="6">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady8"
            @columnResized="onColumnResized7"
            @columnMoved="onColumnMoved7"
            @columnVisible="onColumnVisible7"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableDataList8"
            :columnDefs="tc7"
            :localeText="localeText1"
          >
          </AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet8.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize8"
            @page-size-change="change8"
            style="justify-content: center"
            :page-size="fySelet8.size"
            :current="fySelet8.page"
          />
        </a-tab-pane>
      </a-tabs>
    </template>
    <a-modal
      v-model:visible="cgOut.visible"
      :on-before-ok="cgHandleOk"
      @cancel="cadelvs"
      fullscreen
      :mask-closable="false"
    >
      <template #title>
        {{ cgOut.title }}
      </template>
      <div class="w-full">
        <a-form
          size="small"
          :model="drawerData"
          layout="inline"
          :rules="drawerRules"
          ref="drawerRef"
        >
          <el-row :gutter="0" class="w-full">
            <el-col :xl="4" :lg="4" :md="8" :sm="12" :xs="12">
              <a-form-item label="仓库" field="warehouseTypeId">
                <a-select
                  popup-container="html"
                  class="bacClass"
                  :style="{ width: '200px' }"
                  v-model="drawerData.warehouseTypeId"
                  allow-clear
                >
                  <a-option v-for="item in drawerData.warehouseList" :value="item.id">
                    {{ item.warehouseName }}
                  </a-option>
                </a-select>
              </a-form-item>
            </el-col>
            <el-col
              :xl="20"
              :lg="20"
              :md="16"
              :sm="12"
              :xs="12"
              style="display: flex; justify-content: end; padding-right: 20px"
            >
              <a-form-item style="margin-right: 0">
                <el-button @click="handleOutStockModalSearch" type="primary">查询</el-button>
              </a-form-item>
            </el-col>
          </el-row>
        </a-form>
      </div>
      <div style="width: 100%; height: 600px">
        <encapsulation-agrid
          ref="gridOptionRef2"
          :configaggrid="configaggrid2"
        ></encapsulation-agrid>
      </div>
    </a-modal>
    <a-drawer
      ok-text="保存"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 999 }"
      :mask-closable="false"
      unmount-on-close
      popup-container=".arco-tabs-content"
      :height="'90%'"
      :visible="dbPageDate.showAdd"
      @ok="sideOk"
      placement="bottom"
      @cancel="sideNo"
    >
      <template #title>
        {{ dbPageDate.titles }}
      </template>
      <div style="min-width: 1500px; overflow: auto">
        <el-scrollbar>
          <a-form ref="formRef" layout="inline" :model="searchData" size="mini">
            <CorporateSectorCascader
              :configCascader="configCascader"
              @changeCascader="changeCascader"
            />
            <a-form-item
              label="发货仓库"
              :rules="[{ required: true, message: '仓库必填' }]"
              field="fhWh"
            >
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="searchData.fhWh"
                allow-clear
              >
                <a-option v-for="item in fhWhList" :value="item.id + '-' + item.warehouseName">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <CorporateSectorCascader
              :configCascader="configCascader2"
              @changeCascader="changeCascader2"
            />
            <a-form-item
              label="收货仓库"
              :rules="[{ required: true, message: '仓库必填' }]"
              field="shWh"
            >
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="searchData.shWh"
                allow-clear
              >
                <a-option v-for="item in shWhList" :value="item.id + '-' + item.warehouseName">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
          </a-form>

          <a-space style="margin-bottom: 10px">
            <a-button type="primary" @click="addLine" size="mini">新增</a-button>
            <!-- <a-button type="primary" @click="delLine" size="mini">删除</a-button> -->
          </a-space>
          <a-table
            stripe
            :bordered="true"
            :columns="tableColumnsWl"
            size="mini"
            :data="wlListArray"
            :row-selection="{ showCheckedAll: true, width: 50 }"
            rowKey="typeIds"
            v-model:selected-keys="selectedRowKeysWl"
          >
            <template #pieceNumber="{ record }">
              <a-input-number
                @change="jiHUsn(record)"
                class="bacClass"
                v-model="record.pieceNumber"
                :max="record.a"
              ></a-input-number>
            </template>
            <template #bulkNumber="{ record }">
              <a-input-number
                @change="jiHUsn2(record)"
                class="bacClass"
                v-model="record.bulkNumber"
                :max="record.b"
              ></a-input-number>
            </template>
            <template #bulkWeight="{ record }">
              <a-input-number
                @change="jiHUsn3(record)"
                class="bacClass"
                v-model="record.bulkWeight"
                :max="record.c"
              ></a-input-number>
            </template>
          </a-table>
        </el-scrollbar>
      </div>
    </a-drawer>

    <a-modal
      fullscreen
      v-model:visible="visibleYl"
      :on-before-ok="handleOks"
      @cancel="handleCancels"
      :mask-closable="false"
    >
      <template #title> 选择原料调拨出库入库 </template>
      <a-table
        :style="{
          height: '500px',
          marginTop: '10px',
        }"
        :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }"
        rowKey="id"
        v-model:selected-keys="selectedRowKeys2"
        stripe
        :bordered="true"
        :scrollbar="true"
        sticky-header
        :pagination="false"
        :columns="tableColumns3"
        :data="wlListXqs"
      >
      </a-table>
      <paginationCopys
        :page-size-options="pagingList1"
        :total="fySelet3.total"
        show-total
        show-jumper
        show-page-size
        @change="PageSize3"
        @page-size-change="change3"
        style="justify-content: center"
        :page-size="fySelet3.size"
        :current="fySelet3.page"
      />
    </a-modal>
    <a-modal
      v-model:visible="cgOut.visible2"
      :on-before-ok="cgHandleOk2"
      @cancel="cadelvs2"
      fullscreen
      :mask-closable="false"
    >
      <template #title> 调拨出库 </template>
      <div style="width: 100%; height: 600px">
        <encapsulation-agrid
          ref="gridOptionRef3"
          :configaggrid="configaggrid3"
        ></encapsulation-agrid>
      </div>
    </a-modal>
    <a-modal fullscreen v-model:visible="visible" :on-before-ok="handleOk" @cancel="handleCancel">
      <template #title> 调拨申请 </template>
      <a-form ref="formRef2" layout="inline" :model="searchData" size="mini">
        <CorporateSectorCascader
          ref="corPor"
          :configCascader="configCascader4"
          @changeCascader="changeCascader"
        />
        <a-form-item
          label="申请仓库"
          :rules="[{ required: true, message: '仓库必填' }]"
          field="warehouseId"
        >
          <a-select
            popup-container="html"
            class="bacClass"
            :style="{ width: '200px' }"
            v-model="searchData.warehouseId"
            allow-clear
            @change="handleWarehouseChange"
          >
            <a-option v-for="item in searchData.warehouseList" :value="item.id">
              {{ item.warehouseName }}
            </a-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="开单日期"
          :rules="[{ required: true, message: '日期必填' }]"
          field="orderDate"
        >
          <a-date-picker
            popup-container="html"
            class="bacClass"
            v-model="searchData.orderDate"
            style="width: 200px"
          />
        </a-form-item>
        <a-form-item label="备注" field="remark">
          <a-input class="bacClass" v-model="searchData.remark" style="width: 200px" />
        </a-form-item>
      </a-form>
      <div style="width: 100%; height: 98%; overflow: auto">
        <encapsulation-agrid ref="gridOptionRef" :configaggrid="configaggrid"></encapsulation-agrid>
      </div>
    </a-modal>

    <a-drawer
      ok-text="出库"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 999 }"
      :mask-closable="false"
      unmount-on-close
      popup-container=".arco-tabs-content"
      height="100%"
      :visible="dbPageDateShowAdd"
      @ok="sideOk2"
      placement="bottom"
      @cancel="sideNo2"
    >
      <template #title> 新增出库单 </template>
      <a-form ref="formRef2" size="mini" :model="pageData2" layout="inline">
        <!-- <a-form-item label="公司">
                <a-input allow-clear :style="{ width: '200px' }" class="bacClass" v-model="pageData.a" />
            </a-form-item> -->
        <CorporateSectorCascader
          ref="setcorDisabledRefs"
          :configCascader="configCascader5"
          @changeCascader="changeCascader5"
        />
        <a-form-item label="仓库名称" :rules="[{ required: true, message: '仓库必填' }]" field="b">
          <a-select
            popup-container="html"
            class="bacClass"
            :style="{ width: '10rem' }"
            v-model="pageData2.b"
            allow-clear
          >
            <a-option v-for="item in shWhList5" :value="item.id + '-' + item.warehouseName">
              {{ item.warehouseName }}
            </a-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="客户名称"
          :rules="[{ required: true, message: '客户名称必填' }]"
          field="d"
        >
          <a-select
            popup-container="html"
            class="bacClass"
          @click="customName('')"
           @search="customName($event)"
            :style="{ width: '10rem' }"
            v-model="pageData2.d"
            allow-search
            allow-clear
          >
            <a-option v-for="item in customNameCxList" :value="item.brandName">
              {{ item.brandName }}
            </a-option>
          </a-select>
        </a-form-item>
        <a-form-item label="客户订单号" field="e">
          <a-input class="bacClass" v-model="pageData2.e"></a-input>
        </a-form-item>
        <a-form-item
          label="出库类型"
          :rules="[{ required: true, message: '出库类型必填' }]"
          field="c"
        >
          <a-select
            popup-container="html"
            class="bacClass"
            @click="OutStoCx"
            :style="{ width: '10rem' }"
            v-model="pageData2.c"
            allow-search
            allow-clear
          >
            <a-option v-for="item in outStoCxList" :value="item.typeName">
              {{ item.typeName }}
            </a-option>
          </a-select>
        </a-form-item>
        <a-form-item label="备注" field="e">
          <a-input class="bacClass" v-model="pageData2.f"></a-input>
        </a-form-item>
      </a-form>
      <a-space style="margin-bottom: 10px">
        <a-button type="primary" @click="addLine2" size="mini">新增</a-button>
      </a-space>
      <div style="width: 100%; height: 600px">
        <encapsulation-agrid
          ref="gridOptionRef4"
          :configaggrid="configaggrid4"
        ></encapsulation-agrid>
      </div>
    </a-drawer>
    <a-modal
      fullscreen
      v-model:visible="visibleYl2"
      :on-before-ok="handleOks2"
      @cancel="handleCancels2"
      :mask-closable="false"
    >
      <template #title>选择原料库存</template>
      <div class="cgisDatas">
        <div>
          <span>原料编号:</span
          ><a-input class="bacClass" v-model="isLyCodeds" :style="{ width: '150px' }" allow-clear />
        </div>
        <div>
          <span>原料名称:</span
          ><a-input class="bacClass" v-model="isLyNameds" :style="{ width: '150px' }" allow-clear />
        </div>
        <div>
          <span>纱批:</span
          ><a-input
            class="bacClass"
            v-model="productionBatch"
            :style="{ width: '150px' }"
            allow-clear
          />
        </div>
        <a-button type="primary" @click="cxCgsLists">查询</a-button>
      </div>
      <div style="width: 100%; height: calc(100% - 40px); margin-top: 15px">
        <encapsulation-agrid
          ref="gridOptionRef5"
          :configaggrid="configaggrid5"
        ></encapsulation-agrid>
        <paginationCopys
          :page-size="fySelet7.size"
          :current="fySelet7.page"
          :total="fySelet7.total"
          show-total
          show-jumper
          show-page-size
          @change="PageSize7"
          @page-size-change="change7"
          style="justify-content: center"
        />
      </div>
    </a-modal>

    <a-modal
      ok-text="打印"
      :width="900"
      v-model:visible="visibleYl3"
      :on-before-ok="handleOks3"
      @cancel="handleCancels3"
    >
      <template #title>原料客供退库单</template>
      <div id="wjDyings11">
        <div class="No1">
          <div class="No1-1">佛山市巨丰盛布业有限公司</div>
          <div class="No1-2">原料客供退库单</div>
          <div class="No1-4">
            <div>出库单号:&nbsp;&nbsp;{{ printList[0]?.outStockNumber }}</div>
            <div>客户名称:&nbsp;&nbsp;{{ printList[0]?.customName }}</div>
            <div>客户订单号:&nbsp;&nbsp;{{ printList[0]?.customOrderNo }}</div>
          </div>
        </div>
        <table class="isTable">
          <tr>
            <th>原料名称</th>
            <th>纱牌</th>
            <th>纱批</th>
            <th>色号色称</th>
            <th>件数</th>
            <th>件重</th>
            <th>散件</th>
            <th>散重</th>
            <th>数量</th>
            <th>备注</th>
          </tr>
          <tr v-for="item in printList">
            <td>{{ item.yarnName }}</td>
            <td>{{ item.yarnBrand }}</td>
            <td>{{ item.productionBatch }}</td>
            <td>{{ item.colorCode + '/' + item.colorName }}</td>
            <td>{{ item.pieceNumber }}</td>
            <td>{{ item.pieceWeight }}</td>
            <td>{{ item.bulkNumber }}</td>
            <td>{{ item.bulkWeight }}</td>
            <td>{{ item.weightTotal }}</td>
            <td>{{ item.remark }}</td>
          </tr>
          <tr>
            <td colspan="2" style="text-align: left">备注:{{ printList[0]?.totalRemark }}</td>
            <td colspan="2">合计</td>
            <td>{{ printList[printList.length - 1]?.pieceNumbers }}</td>
            <td></td>
            <td>{{ printList[printList.length - 1]?.bulkNumbers }}</td>
            <td>{{ printList[printList.length - 1]?.bulkWeights }}</td>
            <td>{{ printList[printList.length - 1]?.weightTotals }}</td>
            <td></td>
          </tr>
        </table>
        <div class="No1-3">
          <div>开单人:&nbsp;&nbsp;{{ printList[0]?.createName }}</div>
          <div>签收:</div>
          <div>开单日期:&nbsp;&nbsp;{{ printList[0]?.createDate }}</div>
        </div>
      </div>
    </a-modal>

    <a-modal
      ok-text="打印"
      :width="900"
      v-model:visible="visibleYl4"
      :on-before-ok="handleOks4"
      @cancel="handleCancels4"
    >
      <template #title>原料出库单</template>
      <div id="wjDyings12">
        <div class="No1">
          <div class="No1-1">原料出库单</div>
          <!-- <div class="No1-2">原料客供退库单</div> -->
          <div class="No1-4-1">
            <!-- <div>客户名称:&nbsp;&nbsp;{{ printList[0]?.customName }}</div>
                    <div>客户订单号:&nbsp;&nbsp;{{ printList[0]?.customOrderNo }}</div> -->
            <div>公司:&nbsp;&nbsp;{{ printList2[0]?.firm }}</div>
            <div>仓库:&nbsp;&nbsp;{{ printList2[0]?.warehouse }}</div>
            <div>开单日期:&nbsp;&nbsp;{{ printList2[0]?.createDate }}</div>
            <div>NO:&nbsp;&nbsp;{{ printList2[0]?.outStockNumber }}</div>
          </div>
        </div>
        <table class="isTable">
          <tr>
            <th>客户</th>
            <th>原料名称</th>
            <th>纱牌</th>
            <th>纱批</th>
            <th>色号</th>
            <th>色称</th>
            <th>整件/个数</th>
            <th>整件/件数</th>
            <th>整件/件重</th>
            <th>散件/个数</th>
            <th>散件/件数</th>
            <th>散件/件重</th>
            <th>总数量</th>
            <th>备注</th>
          </tr>
          <tr v-for="item in printList2">
            <td>{{ item.customName }}</td>
            <td>{{ item.yarnName }}</td>
            <td>{{ item.yarnBrand }}</td>
            <td>{{ item.productionBatch }}</td>
            <td>{{ item.colorCode }}</td>
            <td>{{ item.colorName }}</td>
            <td>{{ item.pieceCount }}</td>
            <td>{{ item.pieceNumber }}</td>
            <td>{{ item.pieceWeight }}</td>
            <td>{{ item.bulkCount }}</td>
            <td>{{ item.bulkNumber }}</td>
            <td>{{ item.bulkWeight }}</td>
            <td>{{ item.weightTotal }}</td>
            <td>{{ item.remark }}</td>
          </tr>
          <tr>
            <td>合计</td>
            <td colspan="6">{{ printList2[printList2.length - 1]?.pieceCounts }}</td>
            <td>{{ printList2[printList2.length - 1]?.pieceNumbers }}</td>
            <td></td>
            <td>{{ printList2[printList2.length - 1]?.bulkCounts }}</td>
            <td>{{ printList2[printList2.length - 1]?.bulkNumbers }}</td>
            <td>{{ printList2[printList2.length - 1]?.bulkWeights }}</td>
            <td>{{ printList2[printList2.length - 1]?.weightTotals }}</td>
            <td></td>
          </tr>
        </table>
        <div class="No1-3">
          <div>开单人:&nbsp;&nbsp;{{ printList2[0]?.createName }}</div>
          <div>审核人:&nbsp;&nbsp;{{ printList2[0]?.auditName }}</div>
          <div>仓管:</div>
          <div>收货签章:</div>
        </div>
      </div>
    </a-modal>

    <a-drawer
      ok-text="汇总生产领料单"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 999 }"
      :mask-closable="false"
      unmount-on-close
      popup-container=".arco-tabs-content"
      height="100%"
      :visible="hzAshows"
      @ok="hzSOks"
      placement="bottom"
      @cancel="() => (hzAshows = false)"
    >
      <template #title> 需求单汇总 </template>
      <AgGridVuesCopys
        :rowHeight="33"
        :headerHeight="33"
        :suppressCopyRowsToClipboard="true"
        rowSelection="multiple"
        @grid-ready="gridReadyhz"
        style="height: 98%"
        :defaultColDef="defaultColDef"
        class="ag-theme-alpine"
        :rowData="hzDataList"
        :columnDefs="tchz"
        :localeText="localeText1"
      ></AgGridVuesCopys>
    </a-drawer>
    <a-modal
      :width="500"
      v-model:visible="visiblehz"
      :on-before-ok="handleOkhz"
      @cancel="visiblehz = false"
    >
      <template #title> 需求单汇总 </template>
      <a-form ref="formRefhz" layout="inline" :model="searchDatahz" size="mini">
        <CorporateSectorCascader
          ref="corPorhz"
          :configCascader="configCascaderhz"
          @changeCascader="changeCascaderhz"
        />
        <a-form-item
          label="发货仓库"
          :rules="[{ required: true, message: '仓库必填' }]"
          field="warehouseId"
        >
          <a-select
            popup-container="html"
            class="bacClass"
            :style="{ width: '15rem' }"
            v-model="searchDatahz.warehouseId"
            allow-clear
          >
            <a-option v-for="item in fhWhListhz" :value="item.id">
              {{ item.warehouseName }}
            </a-option>
          </a-select>
        </a-form-item>
      </a-form>
    </a-modal>

    <a-modal
      :width="1200"
      v-model:visible="visibleLlDb"
      :on-before-ok="handleOkLlDb"
      @cancel="handleCancelLlDb"
    >
      <template #title> 调拨申请 </template>
      <a-form layout="inline" :model="searchDataLldb" size="mini">
        <CorporateSectorCascader
          ref="corporLlDb"
          :configCascader="configCascaderLlDb"
          @changeCascader="changeCascaderLlDb"
        />
        <a-form-item
          label="申请仓库"
          :rules="[{ required: true, message: '仓库必填' }]"
          field="warehouseId"
        >
          <a-select
            popup-container="html"
            class="bacClass"
            :style="{ width: '15rem' }"
            v-model="searchDataLldb.warehouseId"
            allow-clear
          >
            <a-option v-for="item in fhWhListLlDb" :value="item.id">
              {{ item.warehouseName }}
            </a-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="开单日期"
          :rules="[{ required: true, message: '日期必填' }]"
          field="orderDate"
        >
          <a-date-picker
            popup-container="html"
            class="bacClass"
            v-model="searchDataLldb.orderDate"
            style="width: 200px"
          />
        </a-form-item>
        <a-form-item label="备注" field="remark">
          <a-input class="bacClass" v-model="searchDataLldb.remark" style="width: 200px" />
        </a-form-item>
      </a-form>
      <a-table
        style="height: 100%"
        :scrollbar="true"
        sticky-header
        stripe
        :columns="tableColumnsLlDb"
        :data="dataLlDb"
        :pagination="false"
        :bordered="{ cell: true }"
      >
        <template #planMaterialPieceNum="{ record }">
          <a-input-number
            @change="pNumberLlDb(record)"
            class="bacClass"
            v-model="record.planMaterialPieceNum"
          ></a-input-number>
        </template>
        <template #planMaterialBulkWeight="{ record }">
          <a-input-number
            @change="bNumberLlDb(record)"
            class="bacClass"
            v-model="record.planMaterialBulkWeight"
          ></a-input-number>
        </template>
        <template #planMaterialBulkNum="{ record }">
          <a-input-number
            @change="buNumberLlDb(record)"
            class="bacClass"
            v-model="record.planMaterialBulkNum"
          ></a-input-number>
        </template>
        <template #remark="{ record }">
          <a-input class="bacClass" v-model="record.remark" />
        </template>
      </a-table>
    </a-modal>
  </pageTabelLayout>
</template>
<script setup lang="ts">
  import { ref, reactive } from 'vue'
  import { post, get } from '@/api/http'
  import { localeText } from '@/api/aggridZw'
  import inputRender from '@/components/aggridCellRenDerer/inputRender.vue'
  import inputRenderCopy from '@/components/aggridCellRenDerer/inputRender copy.vue'
  import Toolbar from '@/components/Toolbar.vue'
  import { Message, Modal } from '@arco-design/web-vue'
  import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
  import WHService from '@/service/wh'
  import usePermission from '@/store/modules/permission'
  import printJS from 'print-js'
  import dayjs from 'dayjs'
  import { pagingList } from '@/api/paging'
  import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState02 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState03 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState04 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState05 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState06 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState07 } from '@/hooks/useGridState'
  import setTableTotalRow from '@/utils/setTableTotalRow.ts'
  const pagingList1: any = ref(pagingList)
  const permissionStore = usePermission()
  const gridOptionRef: any = ref(null)
  const drawerRules = reactive({
    warehouseTypeId: [{ required: true, message: '仓库必填' }],
  })
  const drawerRef = ref<any>(null)
  const tableColumns: any = ref([
    {
      headerName: '客户名称',
      field: 'customName',
      dataIndex: 'customName',
      width: 150,
    },
    {
      headerName: '原料编号',
      field: 'rawMaterialCode',
      dataIndex: 'rawMaterialCode',
      width: 150,
    },
    {
      headerName: '原料名称',
      field: 'rawMaterialName',
      dataIndex: 'rawMaterialName',
      width: 150,
    },
    {
      headerName: '纱牌',
      field: 'brandName',
      dataIndex: 'brandName',
      width: 150,
    },
    {
      headerName: '纱批',
      field: 'yarnBatch',
      dataIndex: 'yarnBatch',
      width: 150,
    },
    {
      headerName: '色号',
      field: 'colorCode',
      dataIndex: 'colorCode',
      width: 150,
    },
    {
      headerName: '色称',
      field: 'colorName',
      dataIndex: 'colorName',
      width: 150,
    },
    {
      headerName: '可配色称',
      field: 'matchColor',
      dataIndex: 'matchColor',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'level',
      dataIndex: 'level',
      width: 150,
    },
    {
      headerName: '申请件数',
      field: 'planMaterialPieceNum',
      dataIndex: 'planMaterialPieceNum',
      slotName: 'planMaterialPieceNum',
      width: 150,
      cellRenderer: {
        template: `
        <a-input-number
          @change="callPnumber2(record)"
          class="bacClass"
          v-model="record.planMaterialPieceNum"
        ></a-input-number>
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callPnumber2 = (a: any) => {
            pNumber2(a)
          }
          return {
            record,
            callPnumber2,
          }
        },
      },
    },
    {
      headerName: '整件/件重',
      field: 'planMaterialPieceWeight',
      dataIndex: 'planMaterialPieceWeight',
      width: 150,
    },
    // {
    //     headerName: "领料散件件数",
    //     field: "planMaterialBulkWeight",
    //     dataIndex: "planMaterialBulkWeight",
    //     slotName: 'planMaterialBulkWeight',
    //     width: 150,
    // },
    // {
    //     headerName: "领料散件件重",
    //     field: "planMaterialBulkNum",
    //     dataIndex: "planMaterialBulkNum",
    //     slotName: 'planMaterialBulkNum',
    //     width: 150,
    // },
    {
      headerName: '申请数量',
      field: 'planMaterialWeight',
      dataIndex: 'planMaterialWeight',
      width: 150,
      cellRenderer: {
        template: `
        <a-input  v-model="record.planMaterialWeight" :disabled='true'/>
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          return {
            record,
          }
        },
      },
    },
    {
      headerName: '单位',
      field: 'unit',
      dataIndex: 'unit',
      width: 150,
    },
    {
      headerName: '备注',
      field: 'remark',
      dataIndex: 'remark',
      slotName: 'remark',
      width: 150,
      cellRenderer: {
        template: `
        <a-input class="bacClass" v-model="record.remark" />
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          return {
            record,
          }
        },
      },
    },
  ])
  let configaggrid = ref({
    url: '', //接口路径
    queryData: {
      //接口参数
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns,
    fileName: 'yscckMaterialRequisitioToBeProcessed',
  })
  const gridOptionRef2: any = ref(null)
  const tableColumns2: any = [
    {
      dataIndex: 'company',
      field: 'company',
      headerName: '公司名称',
      width: 150,
    },
    {
      dataIndex: 'planMaterialCode',
      field: 'planMaterialCode',
      headerName: '领料单号',
      width: 150,
    },
    {
      dataIndex: 'outStockType',
      field: 'outStockType',
      slotName: 'outStockType',
      headerName: '出库类型',
      width: 150,
      cellRenderer: {
        template: `
          <div>
            <a-select
            popup-container="html"
            class="bacClass"
            allow-clear
            v-model="record.outStockType"
            allow-search
          >
            <a-option v-for="item in outStockTypeList" :value="item.typeName">
              {{ item.typeName }}
            </a-option>
          </a-select>
          </div>
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          return {
            record,
            outStockTypeList,
          }
        },
      },
    },
    {
      dataIndex: 'supplier',
      field: 'supplier',
      headerName: '供应商名称 ',
      // slotName: 'supplier',
      width: 150,
    },
    {
      dataIndex: 'customName',
      field: 'customName',
      headerName: '客户名称 ',
      width: 150,
    },
    {
      dataIndex: 'rawMaterialCode',
      field: 'rawMaterialCode',
      headerName: '原料编号 ',
      width: 150,
    },
    {
      dataIndex: 'rawMaterialName',
      field: 'rawMaterialName',
      headerName: '原料名称 ',
      width: 150,
    },
    {
      dataIndex: 'brandName',
      field: 'brandName',
      headerName: '纱牌',
      width: 150,
    },
    {
      dataIndex: 'yarnBatch',
      field: 'yarnBatch',
      headerName: '纱批 ',
      width: 150,
    },
    {
      dataIndex: 'level',
      field: 'level',
      headerName: '等级 ',
      // slotName: 'level',
      width: 150,
    },
    {
      dataIndex: 'matchColor',
      field: 'matchColor',
      headerName: '可配色称 ',
      // slotName: 'matchColor',
      width: 150,
    },
    {
      dataIndex: 'colorCode',
      field: 'colorCode',
      headerName: '色号 ',
      width: 150,
    },
    {
      dataIndex: 'colorName',
      field: 'colorName',
      headerName: '色称 ',
      width: 150,
    },

    {
      dataIndex: 'unit',
      field: 'unit',
      // slotName: 'unit',
      headerName: '单位',
      width: 150,
    },

    {
      dataIndex: 'planMaterialPieceWeight',
      field: 'planMaterialPieceWeight',
      headerName: '整件/件重',
      width: 150,
    },
    {
      dataIndex: 'pieceCount',
      field: 'pieceCount',
      headerName: '整件/个数',
      width: 150,
    },

    {
      headerName: '领料',
      children: [
        {
          dataIndex: 'planMaterialPieceNum',
          field: 'planMaterialPieceNum',
          headerName: '整件/件数 ',
          width: 150,
        },
        {
          dataIndex: 'planMaterialWeight',
          field: 'planMaterialWeight',
          headerName: '总重量 ',
          width: 150,
        },
      ],
    },
    {
      headerName: '未领料',
      children: [
        {
          headerName: '总重量',
          field: 'unPlanMaterialWeight',
          width: 150,
          valueGetter: function (params: any) {
            return toFixedNum(params.data.planMaterialWeight - params.data.outStockWeight)
          },
        },
      ],
    },
    {
      headerName: '已出库',
      children: [
        {
          dataIndex: 'outStockPieceNum',
          field: 'outStockPieceNum',
          headerName: '整件/件数',
          width: 150,
        },
        {
          dataIndex: 'outStockPieceWeight',
          field: 'outStockPieceWeight',
          headerName: '整件/总重量',
          width: 150,
          valueGetter: function (params: any) {
            return toFixedNum(params.data.outStockPieceNum * params.data.planMaterialPieceWeight)
          },
        },
        {
          dataIndex: 'outStockBulkNumber',
          field: 'outStockBulkNumber',
          headerName: '散件/件数',
          width: 150,
        },
        {
          dataIndex: 'outStockBulkCount',
          field: 'outStockBulkCount',
          headerName: '散件/个数',
          width: 150,
        },
        {
          dataIndex: 'outStockBulkWeight',
          field: 'outStockBulkWeight',
          headerName: '散件/散重',
          width: 150,
        },
        {
          dataIndex: 'outStockWeight',
          field: 'outStockWeight',
          headerName: '总重量 ',
          width: 150,
        },
      ],
    },

    {
      headerName: '库存',
      children: [
        {
          dataIndex: 'stockPieceNumber',
          field: 'stockPieceNumber',
          headerName: '整件/件数',
          width: 150,
        },
        {
          dataIndex: 'stockPieceWeight',
          field: 'stockPieceWeight',
          headerName: '整件/总重量',
          width: 150,
        },
        {
          dataIndex: 'stockBulkNumber',
          field: 'stockBulkNumber',
          headerName: '散件/件数',
          width: 150,
        },
        {
          dataIndex: 'stockBulkCount',
          field: 'stockBulkCount',
          headerName: '散件/个数',
          width: 150,
        },
        {
          dataIndex: 'stockBulkWeight',
          field: 'stockBulkWeight',
          headerName: '散件/散重 ',
          width: 150,
        },
        {
          dataIndex: 'stockTotalWeight',
          field: 'stockTotalWeight',
          headerName: '库存总重量 ',
          width: 150,
        },
      ],
    },
    {
      headerName: '出库',
      children: [
        {
          dataIndex: 'pieceNumber',
          field: 'pieceNumber',
          slotName: 'pieceNumber',
          headerName: '整件/件数',
          width: 150,
          fixed: 'right',
          cellRenderer: inputRender,
          cellRendererParams: {
            maxNumberKey: 'stockPieceNumber',
          },
          valueSetter: (params: any) => {
            const newValue = params.newValue
            params.data.pieceNumber = newValue
            if (Number(newValue) > Number(params.data.pieceNumber)) {
              params.data.pieceNumber = params.data.stockPieceNumber
              return true
            }

            if (
              params.data.pieceNumber &&
              params.data.bulkWeight &&
              params.data.stockPieceWeight != 0
            ) {
              params.data.weightTotal = toFixedNum(
                params.data.pieceNumber * params.data.stockPieceWeight +
                  params.data.bulkWeight
              )
            } 
            // else if (params.data.pieceNumber && params.data.stockPieceWeight != 0) {
            //   params.data.weightTotal = toFixedNum(
            //     params.data.pieceNumber * params.data.stockPieceWeight
            //   )
            // } 
            else if (params.data.bulkWeight) {
              params.data.weightTotal = toFixedNum(params.data.bulkWeight)
            } else {
              params.data.weightTotal = 0
            }
            params.data.weightPieceTotal = toFixedNum(
              params.data.pieceNumber * params.data.stockPieceWeight
            )
            return true
          },
        },
        {
          dataIndex: 'weightPieceTotal',
          field: 'weightPieceTotal',
          slotName: 'weightPieceTotal',
          headerName: '整件/总重量',
          width: 150,
          fixed: 'right',
          cellRenderer: {
            template: `
        <a-input  v-model="weightPieceTotal" :disabled='true'/>
        `,
            setup(props: any) {
              const weightPieceTotal = ref(
                toFixedNum(
                  props.params.data.pieceNumber * props.params.data.stockPieceWeight
                )
              )
              return {
                weightPieceTotal,
              }
            },
          },
        },
        {
          dataIndex: 'bulkNumber',
          field: 'bulkNumber',
          slotName: 'bulkNumber',
          headerName: '散件/件数',
          width: 150,
          fixed: 'right',
          cellRenderer: inputRender,
          cellRendererParams: {
            maxNumberKey: 'stockBulkNumber',
          },
          valueSetter: (params: any) => {
            const newValue = params.newValue
            params.data.bulkNumber = newValue
            if (newValue == 0) {
              
              let tmBulkWeight= params.data.bulkWeight
              params.data.bulkWeight = 0
              params.data.bulkCount = 0
              
              params.data.weightTotal=toFixedNum(params.data.weightTotal-tmBulkWeight)
            }
            if (Number(newValue) >= Number(params.data.stockBulkNumber)) {
              // params.data.bulkNumber = params.data.stockBulkNumber
              params.data.bulkWeight = params.data.stockBulkWeight
              // params.data.bulkCount = params.data.stockBulkCount
              
            }
            params.data.weightTotal=Number((params.data.bulkWeight+params.data.weightPieceTotal).toFixed(2))
            return true
          },
        },
        {
          dataIndex: 'bulkCount',
          field: 'bulkCount',
          slotName: 'bulkCount',
          headerName: '散件/个数',
          width: 150,
          fixed: 'right',
          cellRenderer: inputRender,
          // cellRendererParams: {
          //   maxNumberKey: 'stockBulkCount',
          // },
          valueSetter: (params: any) => {
            const newValue = params.newValue
            params.data.bulkCount = newValue
            console.log("散件/个数1:"+newValue);
            
            // if (Number(newValue) >= Number(params.data.stockBulkCount)) {
            //   // params.data.bulkCount = params.data.stockBulkCount
            //   params.data.bulkWeight = params.data.stockBulkWeight
            //   params.data.bulkNumber = params.data.stockBulkNumber
            // }
            if (newValue == 0) {
              let tmBulkWeight= params.data.bulkWeight
              params.data.bulkWeight = 0
              params.data.bulkNumber = 0
              params.data.weightTotal=toFixedNum(params.data.weightTotal-tmBulkWeight)

            }
            return true
          },
        },
        {
          dataIndex: 'bulkWeight',
          field: 'bulkWeight',
          slotName: 'bulkWeight',
          headerName: '散件/散重',
          width: 150,
          fixed: 'right',
          cellRenderer: inputRender,
          cellRendererParams: {
            maxNumberKey: 'stockBulkWeight',
          },
          valueSetter: (params: any) => {
            const newValue = params.newValue
            let tmBulkWeight= params.data.bulkWeight
            params.data.bulkWeight = newValue
            params.data.weightTotal=toFixedNum(params.data.weightTotal-tmBulkWeight+newValue)

           if (params.data.bulkWeight && params.data.bulkWeight == 0) {
              params.data.bulkNumber = 0
              params.data.bulkCount = 0
              params.data.weightTotal=toFixedNum(params.data.weightTotal-tmBulkWeight)
            } else if (
              params.data.bulkWeight &&
              params.data.stockBulkWeight &&
              params.data.bulkWeight >= params.data.stockBulkWeight
            ) {
              params.data.bulkNumber = params.data.stockBulkNumber
              // params.data.bulkCount = params.data.stockBulkCount
              params.data.bulkWeight = params.data.stockBulkWeight
            } 
            params.data.weightTotal=Number((params.data.bulkWeight+params.data.weightPieceTotal).toFixed(2))
            return true
          },
        },
        {
          dataIndex: 'weightTotal',
          field: 'weightTotal',
          slotName: 'weightTotal',
          headerName: '总重量',
          width: 150,
          fixed: 'right',
          cellRenderer: {
            template: `
        <a-input  v-model="weightTotal" :disabled='true'/>
        `,
            setup(props: any) {
              const weightTotal = ref(props.params.data.weightTotal.toFixed(2))
              return {
                weightTotal,
              }
            },
          },
        },
      ],
    },
    {
      dataIndex: 'remark',
      field: 'remark',
      headerName: '备注 ',
      slotName: 'remark',
      width: 150,
    },
  ]
  let configaggrid2 = ref({
    url: '', //接口路径
    queryData: {
      //接口参数
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns2,
    fileName: 'yscckMaterialRequisitioToBeProcessed2',
  })
  const gridOptionRef3: any = ref(null)
  const tableColumns4: any = [
    {
      field: 'transferNumber',
      key: 'transferNumber',
      headerName: '调拨单号',
      width: 150,
    },
    {
      field: 'outFirm',
      key: 'outFirm',
      headerName: '转出公司',
      width: 150,
    },
    {
      field: 'outWarehouse',
      key: 'outWarehouse',
      headerName: '转出仓库',
      width: 150,
    },
    {
      field: 'inFirm',
      key: 'inFirm',
      headerName: '收货公司',
      width: 150,
    },
    {
      field: 'inWarehouse',
      key: 'inWarehouse',
      headerName: '收货仓库',
      width: 150,
    },
    {
      field: 'sourceNumber',
      key: 'sourceNumber',
      headerName: '来源单号',
      width: 150,
    },
    {
      field: 'transferNumber',
      key: 'transferNumber',
      headerName: '调拨单号',
      width: 150,
    },
    {
      field: 'trader',
      key: 'trader',
      headerName: '贸易商',
      width: 150,
    },
    {
      field: 'inventoryOrganization',
      key: 'inventoryOrganization',
      headerName: '库存组织',
      width: 150,
    },
    {
      field: 'customName',
      key: 'customName',
      headerName: '客户名称',
      width: 150,
    },
    {
      field: 'yarnCode',
      key: 'yarnCode',
      headerName: '原料编号',
      width: 150,
    },
    {
      field: 'yarnName',
      key: 'yarnName',
      headerName: '原料名称',
      width: 150,
    },
    {
      field: 'yarnBrand',
      key: 'yarnBrand',
      headerName: '纱牌',
      width: 150,
    },
    {
      field: 'productionBatch',
      key: 'productionBatch',
      headerName: '纱批',
      width: 150,
    },
    {
      field: 'level',
      key: 'level',
      headerName: '等级',
      width: 150,
    },
    {
      field: 'matchColor',
      key: 'matchColor',
      headerName: '可配色称',
      width: 150,
    },
    {
      field: 'colorCode',
      key: 'colorCode',
      headerName: '色号',
      width: 150,
    },
    {
      field: 'colorName',
      key: 'colorName',
      headerName: '色称',
      width: 150,
    },
    {
      field: 'paperBone',
      headerName: '纸骨',
      pinned: 'right',
      width: 200,
      cellRenderer: {
        template: `
        <a-select popup-container="html" class="bacClass" @click="clickEvent()" :style="{ width: '10rem' }"
                  v-model="record.paperBone"
                  allow-search allow-clear allow-create @search="clickEvent()" name="input"
                  @keyup.enter="clickEvent()">
          <a-option v-for="item in paperBoneList" :value="item">
            {{ item }}
          </a-option>
        </a-select>
      `,
        setup(props: any) {
          const record = ref()
          record.value = props.params.data
          const paperBoneList = ref([])
          const clickEvent = () => {
            const {
              yarnCode,
              yarnBrand,
              productionBatch,
              matchColor,
              colorCode,
              colorName,
              paperBone,
            } = record.value
            post({
              url: 'wms/yarnTransferStockDetail/getPaperBoneByDetail',
              data: {
                yarnCode,
                yarnBrand,
                productionBatch,
                matchColor,
                colorCode,
                colorName,
                paperBone,
              },
            }).then((res: any) => {
              if (res.code === 200) {
                paperBoneList.value = res.data
                if (paperBoneList.value.length === 1) {
                  record.value.paperBone = paperBoneList.value[0]
                }
              } else {
                Message.error(res.message)
              }
            })
          }

          clickEvent()
          return {
            record,
            paperBoneList,
            clickEvent,
            Message,
          }
        },
      },
    },
    {
      field: 'pieceNumber',
      key: 'pieceNumber',
      headerName: '整件/件数',
      slotName: 'pieceNumber',
      pinned: 'right',
      width: 150,
      cellRenderer: {
        template: `
        <a-input-number
          @change="callCahngesCount"
          class="bacClass"
          v-model="record.pieceNumber"
          :min="0"
        ></a-input-number>
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callCahngesCount = () => {
            cahngesCount3(record)
          }
          return {
            record,
            callCahngesCount,
          }
        },
      },
    },
    {
      field: 'pieceWeight',
      key: 'pieceWeight',
      headerName: '整件/件重',
      pinned: 'right',
      slotName: 'pieceWeight',
      width: 150,
    },
    {
      field: 'bulkNumber',
      key: 'bulkNumber',
      headerName: '散件/件数',
      slotName: 'bulkNumber',
      pinned: 'right',
      width: 150,
      cellRenderer: {
        template: `
        <a-input-number class="bacClass" v-model="record.bulkNumber" :min="0"></a-input-number>
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          return {
            record,
          }
        },
      },
    },
    {
      field: 'bulkWeight',
      key: 'bulkWeight',
      headerName: '散件/件重',
      slotName: 'bulkWeight',
      pinned: 'right',
      width: 150,
      cellRenderer: {
        template: `
        <a-input-number
          @change="callCahngesCount"
          class="bacClass"
          v-model="record.bulkWeight"
          :min="0"
        ></a-input-number>
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callCahngesCount = () => {
            cahngesCount3(record)
          }
          return {
            record,
            callCahngesCount,
          }
        },
      },
    },
    {
      field: 'weightTotal',
      key: 'weightTotal',
      headerName: '调拨数量',
      pinned: 'right',
      width: 150,
    },
    {
      field: 'weightTotal1',
      key: 'weightTotal1',
      headerName: '总数量',
      width: 150,
    },
    {
      field: 'unit',
      key: 'unit',
      headerName: '单位',
      width: 150,
    },
    {
      field: 'location',
      key: 'location',
      headerName: '库位',
      width: 150,
    },
    {
      field: 'outDate',
      key: 'outDate',
      headerName: '出库时间',
      width: 150,
    },
    {
      field: 'outName',
      key: 'outName',
      headerName: '出库人',
      width: 150,
    },
    {
      field: 'inDate',
      key: 'inDate',
      headerName: '收货时间',
      width: 150,
    },
    {
      field: 'inName',
      key: 'inName',
      headerName: '收货人',
      width: 150,
    },
    {
      field: 'createName',
      key: 'createName',
      headerName: '创单人',
      width: 150,
    },
    {
      field: 'createDate',
      key: 'createDate',
      headerName: '创单时间',
      width: 150,
    },
    {
      field: 'remark',
      key: 'remark',
      headerName: '单据备注',
      width: 150,
    },
    {
      field: 'detailRemake',
      key: 'detailRemake',
      headerName: '明细备注',
      width: 150,
    },
  ]
  let configaggrid3 = ref({
    url: '', //接口路径
    queryData: {
      //接口参数
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns4,
    fileName: 'yscckMaterialRequisitioToBeProcessed3',
  })
  const gridOptionRef4: any = ref(null)
  const tableColumns6: any = [
    {
      field: 'customName',
      key: 'customName',
      slotName: 'customName',
      headerName: '客户名称 ',
      width: 150,
    },
    {
      field: 'yarnCode',
      key: 'yarnCode',
      headerName: '原料编号',
      width: 150,
    },

    {
      field: 'yarnName',
      key: 'yarnName',
      headerName: '原料名称',
      width: 150,
    },
    {
      field: 'yarnBrand',
      key: 'yarnBrand',
      headerName: '纱牌',
      slotName: 'yarnBrand',
      width: 150,
    },
    {
      field: 'productionBatch',
      key: 'productionBatch',
      headerName: '纱批',
      slotName: 'productionBatch',
      width: 150,
    },
    {
      field: 'level',
      key: 'level',
      slotName: 'level',
      headerName: '等级',
      width: 150,
    },
    {
      field: 'transportName',
      key: 'transportName',
      headerName: '搬运计件',
      slotName: 'transportName',
      width: 220,
      cellRenderer: {
        template: `
        <a-select
          popup-container="html"
          class="bacClass"
          v-model="record.transportName"
          allow-clear
          allow-search
          @focus="callFocusTransportName"
          style="width: 180px"
          :title="record.transportName"
        >
          <a-option
            v-for="(item, index) in pageData.transportNameList"
            :value="item.transportName"
            >{{ item.transportName }}</a-option
          >
        </a-select>
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callFocusTransportName = () => {
            focusTransportName()
          }
          return {
            record,
            callFocusTransportName,
            pageData,
          }
        },
      },
    },
    {
      field: 'matchColor',
      key: 'matchColor',
      headerName: '可配色称',
      slotName: 'matchColor',
      width: 150,
    },
    {
      field: 'colorCode',
      key: 'colorCode',
      slotName: 'colorCode',
      headerName: '色号',
      // fixed: 'right',
      width: 150,
    },
    {
      field: 'colorName',
      key: 'colorName',
      slotName: 'colorName',
      headerName: '色称',
      width: 150,
    },
    {
      field: 'pieceCount',
      key: 'pieceCount',
      headerName: '整件/个数',
      slotName: 'pieceCount',
      width: 150,
    },
    {
      field: 'pieceNumber',
      key: 'pieceNumber',
      headerName: '整件/件数',
      slotName: 'pieceNumber',
      width: 150,
      cellRenderer: {
        template: `
        <a-input-number
          :min="0"
          :max="record.pieceNumber2"
          @change="callJiHUsn"
          class="bacClass"
          v-model="record.pieceNumber"
          :precision="0"
        ></a-input-number>
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callJiHUsn = () => {
            cahngesCount4(record)
          }
          return {
            record,
            callJiHUsn,
          }
        },
      },
    },
    {
      field: 'pieceWeight',
      key: 'pieceWeight',
      headerName: '整件/件重',
      slotName: 'pieceWeight',
      width: 150,
    },
    {
      field: 'bulkCount',
      key: 'bulkCount',
      headerName: '散件/个数',
      slotName: 'bulkCount',
      width: 150,
      cellRenderer: inputRender,
      cellRendererParams: {
        maxNumberKey: 'bulkCount2',
      },
      valueSetter: (params: any) => {
        params.data.bulkCount = Number((params.newValue).toFixed(0))
        return true
      },  
    },
    {
      field: 'bulkNumber',
      key: 'bulkNumber',
      headerName: '散件/件数',
      slotName: 'bulkNumber',
      width: 150,
      cellRenderer: inputRender,
      cellRendererParams: {
        maxNumberKey: 'bulkNumber2',
      },
      valueSetter: (params: any) => {
        params.data.bulkNumber = Number((params.newValue).toFixed(0))
        return true
      },  
    },
    {
      field: 'bulkWeight',
      key: 'bulkWeight',
      headerName: '散件/散重',
      slotName: 'bulkWeight',
      width: 150,
      cellRenderer: inputRender,
      cellRendererParams: {
        maxNumberKey: 'bulkWeight2',
      },
      valueSetter: (params: any) => {
        params.data.bulkWeight = Number((params.newValue).toFixed(2))
        params.data.pieceNumber== undefined ? 0 : params.data.pieceNumber
        params.data.pieceWeight== undefined ? 0 : params.data.pieceWeight
        params.data.bulkWeight== undefined ? 0 : params.data.bulkWeight
        if (params.data.bulkWeight) {
          params.data.weightTotal = Number((params.data.pieceNumber * params.data.pieceWeight + params.data.bulkWeight).toFixed(2))
        } else {
          if (params.data.pieceNumber && params.data.pieceWeight) {
            params.data.weightTotal = Number((params.data.pieceNumber * params.data.pieceWeight).toFixed(2))
          }
        }
        return true
      },    
    },
    {
      field: 'weightTotal',
      key: 'weightTotal',
      headerName: '总重量',
      width: 150,
    },
    {
      field: 'unit',
      key: 'unit',
      headerName: '单位',
      slotName: 'unit',
      width: 150,
    },
    {
      field: 'location',
      key: 'location',
      slotName: 'location',
      headerName: '库位',
      width: 150,
    },
    {
      field: 'remark',
      key: 'remark',
      slotName: 'remark',
      headerName: '备注',
      width: 150,
      cellRenderer: {
        template: `
        <a-input class="bacClass" v-model="record.remark"></a-input>
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          return {
            record,
          }
        },
      },
    },
    {
      field: 'acFighs',
      key: 'acFighs',
      slotName: 'acFighs',
      headerName: '操作',
      fixed: 'right',
      width: 100,
    },
  ]
  let configaggrid4 = ref({
    url: '', //接口路径
    queryData: {
      //接口参数
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns6,
    fileName: 'yscckMaterialRequisitioToBeProcessed4',
  })
  const gridOptionRef5: any = ref(null)
  const tableColumns5: any = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      field: 'firm',
      key: 'firm',
      slotName: 'firm',
      headerName: '公司 ',
      width: 150,
    },
    {
      field: 'warehouse',
      key: 'warehouse',
      slotName: 'warehouse',
      headerName: '仓库名称 ',
      width: 150,
    },
    {
      field: 'customName',
      key: 'customName',
      slotName: 'customName',
      headerName: '客户名称 ',
      width: 150,
    },
    {
      field: 'yarnCode',
      key: 'yarnCode',
      headerName: '原料编号',
      width: 150,
    },
    {
      field: 'yarnName',
      key: 'yarnName',
      headerName: '原料名称',
      width: 150,
    },
    {
      field: 'yarnBrand',
      key: 'yarnBrand',
      headerName: '纱牌',
      slotName: 'yarnBrand',
      width: 150,
    },
    {
      field: 'productionBatch',
      key: 'productionBatch',
      headerName: '纱批',
      slotName: 'productionBatch',
      width: 150,
    },
    {
      field: 'level',
      key: 'level',
      slotName: 'level',
      headerName: '等级',
      width: 150,
    },
    {
      field: 'matchColor',
      key: 'matchColor',
      headerName: '可配色称',
      slotName: 'matchColor',
      width: 150,
    },
    {
      field: 'colorCode',
      key: 'colorCode',
      slotName: 'colorCode',
      headerName: '色号',
      // fixed: 'right',
      width: 150,
    },
    {
      field: 'colorName',
      key: 'colorName',
      slotName: 'colorName',
      headerName: '色称',
      width: 150,
    },
    {
      field: 'pieceCount',
      key: 'pieceCount',
      headerName: '整件/个数',
      slotName: 'pieceCount',
      width: 150,
    },
    {
      field: 'pieceNumber',
      key: 'pieceNumber',
      headerName: '整件/件数',
      slotName: 'pieceNumber',
      width: 150,
    },
    {
      field: 'pieceWeight',
      key: 'pieceWeight',
      headerName: '整件/件重',
      slotName: 'pieceWeight',
      width: 150,
    },
    {
      field: 'bulkCount',
      key: 'bulkCount',
      headerName: '散件/个数',
      slotName: 'bulkCount',
      width: 150,
    },
    {
      field: 'bulkNumber',
      key: 'bulkNumber',
      headerName: '散件/件数',
      slotName: 'bulkNumber',
      width: 150,
    },
    {
      field: 'bulkWeight',
      key: 'bulkWeight',
      headerName: '散件/散重',
      slotName: 'bulkWeight',
      width: 150,
    },
    {
      field: 'weightTotal',
      key: 'weightTotal',
      headerName: '总重量',
      width: 150,
    },
    {
      field: 'unit',
      key: 'unit',
      headerName: '单位',
      slotName: 'unit',
      width: 150,
    },
    {
      field: 'location',
      key: 'location',
      slotName: 'location',
      headerName: '库位',
      width: 150,
    },
    {
      field: 'remark',
      key: 'remark',
      slotName: 'remark',
      headerName: '备注',
      width: 150,
    },
  ]
  let configaggrid5 = ref({
    url: '', //接口路径
    queryData: {
      //接口参数
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns5,
    fileName: 'yscckMaterialRequisitioToBeProcessed5',
  })
  const corPor: any = ref()
  const corporLlDb: any = ref()
  const toolbarList: any = ref([
    '打印',
    `${permissionStore.hasPermisson('yscck.yclcx') ? '查询' : ''}`,
    `${permissionStore.hasPermisson('yscck.yclsh') ? '审核' : ''}`,
  ])

  const fySelet: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize = (val: any) => {
    fySelet.page = val
    cxCgsList()
  }

  const change = (val: any) => {
    fySelet.size = val
    cxCgsList()
  }

  const fySelet2: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize2 = (val: any) => {
    fySelet2.page = val
    cxYcList()
  }

  const change2 = (val: any) => {
    fySelet2.size = val
    cxYcList()
  }

  const fySelet4: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize4 = (val: any) => {
    fySelet4.page = val
    cxCgsList2()
  }

  const change4 = (val: any) => {
    fySelet4.size = val
    cxCgsList2()
  }

  const fySelet6: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize6 = (val: any) => {
    fySelet6.page = val
    tkOutus()
  }

  const change6 = (val: any) => {
    fySelet6.size = val
    tkOutus()
  }

  const fySelet8: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize8 = (val: any) => {
    fySelet8.page = val
    OemList()
  }

  const change8 = (val: any) => {
    fySelet8.size = val
    OemList()
  }

  const tkOutus = () => {
    var startDate = pageDataLl.dateList1[0]
    var endDate = pageDataLl.dateList1[1]
    post({
      url: 'wms/yarnOutStock/getPage',
      data: {
        page: fySelet6.page,
        size: fySelet6.size,
        orderType: 1,
        firmId: pageData.a,
        warehouseId: pageData.b,
        yarnCode: pageData.yarnCode,
        yarnName: pageData.yarnName,
        yarnBrand: pageData.yarnBrand,
        outStockTypeList:pageData.outStockTypes,
        productionBatch: pageData.productionBatch,

        level: pageData.level,
        startDate: compareDate(startDate, endDate) == true ? endDate : startDate,
        endDate: compareDate(startDate, endDate) == true ? startDate : endDate,
      },
    }).then((res: any) => {
      gridOption6.value.setRowData(res.data.list)
      setTableTotalRow(gridOption6, res.data.list, [
        'pieceNumber',
        'bulkNumber',
        'bulkWeight',
        'weightTotal',
      ])
      fySelet6.total = res.data.total
    })
  }

  const OemList = () => {
    if (pageDataLl.dateList1.length == 0) {
      var startDate = ''
      var endDate = ''
    } else {
      var startDate = pageDataLl.dateList1[0]
      var endDate = pageDataLl.dateList1[1]
    }
    post({
      url: 'wms/yarnOutStock/getPage',
      data: {
        page: fySelet8.page,
        size: fySelet8.size,
        orderType: 2,
        firmId: pageData.a,
        warehouseId: pageData.b,
        yarnCode: pageData.yarnCode,
        yarnName: pageData.yarnName,
        yarnBrand: pageData.yarnBrand,
        productionBatch: pageData.productionBatch,
        outStockTypeList:pageData.outStockTypes,
        level: pageData.level,
        startDate: compareDate(startDate, endDate) == true ? endDate : startDate,
        endDate: compareDate(startDate, endDate) == true ? startDate : endDate,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        gridOption8.value.setRowData(data.list)
        setTableTotalRow(gridOption8, data.list, [
          'pieceNumber',
          'bulkNumber',
          'bulkWeight',
          'bulkCount',
          'weightTotal',
        ])
        fySelet8.total = data.total
      }
    })
  }
  const headerShow = ref(true)

  const pageData: any = reactive({
    a: '',
    b: '',
    c: '',
    d: '',
    e: null,
    f: null,
    g: null,
    h: null,
    yarnCode: '',
    yarnName: '',
    yarnBrand: '',
    productionBatch: '',
    level: '',
    orderType: null,
    dropDownTime: {},
    transportNameList: [],
    auditState: 0,
    useState: '-1',
    plan_material_code: '',
    out_stock_number: '',
    outStockTypes:[],
    outStockList:[],
  })

  const tableDataList = ref([])

  const tableDataList2 = ref([])

  const gridOption = ref()
  const colState = ref()
  const gridReady = (params: any) => {
    gridOption.value = params.api
    colState.value = params.columnApi
  }

  const gridOption2 = ref()
  const colState3 = ref()
  const gridReady2 = (params: any) => {
    gridOption2.value = params.api
    colState3.value = params.columnApi
  }

  const defaultColDef = {
    sortable: true,
    resizable: true,
    filter: true,
  }

  const defaultColDef2 = {
    sortable: true,
    resizable: true,
    filter: true,
  }

  const localeText1: any = ref(localeText)

  const tc = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '领料单号',
      field: 'planMaterialCode',
      // pinned: o['fixed'],
      width: 150,
    },
    // {
    //     headerName: '类型',
    //     field: 'infoType',
    //     width: 150,
    //     cellRenderer: {
    //         template: `<span>{{states==1?'领料出库':states==2?'调拨出库':''}}</span>`,
    //         setup(props: any) {
    //             return {
    //                 states: props.params.data.infoType
    //             }
    //         }
    //     }
    // },
    {
      headerName: '出库单号',
      field: 'outStockNumber',
      width: 150,
    },
    {
      headerName: '公司',
      field: 'firm',
      width: 150,
    },
    {
      headerName: '仓库',
      field: 'warehouse',
      width: 150,
    },
    {
      headerName: '出库类型',
      field: 'outStockType',
      width: 150,
    },
    {
      headerName: '供应商名称',
      field: 'supplier',
      width: 150,
    },
    {
      headerName: '客户名称',
      field: 'customName',
      width: 150,
    },
    {
      headerName: '原料编号',
      field: 'yarnCode',
      width: 150,
    },
    {
      headerName: '原料名称',
      field: 'yarnName',
      width: 150,
    },
    {
      headerName: '纱牌',
      field: 'yarnBrand',
      width: 150,
    },
    {
      headerName: '纱批',
      field: 'productionBatch',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'level',
      width: 150,
    },
    {
      headerName: '可配色称',
      field: 'matchColor',
      width: 150,
    },
    {
      headerName: '色号',
      field: 'colorCode',
      width: 150,
    },
    {
      headerName: '色称',
      field: 'colorName',
      width: 150,
    },
    {
      headerName: '整件/件数',
      field: 'pieceNumber',
      width: 150,
    },
    {
      headerName: '整件/件重',
      field: 'pieceWeight',
      width: 150,
    },
    {
      headerName: '整件/个数',
      field: 'pieceCount',
      width: 150,
    },
    {
      headerName: '散件/件数',
      field: 'bulkNumber',
      width: 150,
    },
    {
      headerName: '散件/散重',
      field: 'bulkWeight',
      width: 150,
    },
    {
      headerName: '散件/个数',
      field: 'bulkCount',
      width: 150,
    },

    {
      headerName: '总数量',
      field: 'weightTotal',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '备注',
      field: 'remark',
      width: 150,
    },
    {
      headerName: '开单人',
      field: 'createName',
      width: 150,
    },
    {
      headerName: '开单日期',
      field: 'createDate',
      width: 150,
    },
    {
      headerName: '审核人员',
      field: 'auditName',
      width: 150,
    },
    {
      headerName: '审核日期',
      field: 'auditDate',
      width: 150,
    },
    {
      headerName: '审核状态',
      field: 'auditState',
      pinned: 'right',
      width: 150,
      cellRenderer: {
        template: `
            <a-button v-if="states == 1" status="success">已审核出库</a-button>
            <a-button v-else="states == 0" type="dashed" status="success">未审核</a-button>
            `,
        setup(props: any) {
          return {
            states: props.params.data.auditState,
          }
        },
      },
      cellStyle: (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '0' ? '未审核' : params.value == '1' ? '已审核出库' : ''
        },
      },
    },
  ]

  const tc2 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '公司名称',
      field: 'company',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '领料单号',
      field: 'planMaterialCode',
      // pinned: o['fixed'],
      width: 150,
    },
    // {
    //     headerName: '织布单号',
    //     field: 'planOrderCode',
    //     // pinned: o['fixed'],
    //     width: 150
    // },
    // {
    //     headerName: '出库单号',
    //     field: 'orderNo',
    //     width: 150
    // },
    // {
    //     headerName: '来源单号',
    //     field: 'sourceOrderNo',
    //     width: 150
    // },
    // {
    //     headerName: '领料日期',
    //     field: 'planMaterialDate',
    //     width: 150
    // },
    // {
    //     headerName: '领料人',
    //     field: 'planMaterialPerson',
    //     width: 150
    // },
    // {
    //     headerName: '领料部门',
    //     field: 'planMaterialdepartment',
    //     width: 150
    // },supplierName
    {
      headerName: '供应商名称',
      field: 'supplierName',
      width: 150,
    },
    {
      headerName: '客户名称',
      field: 'customName',
      width: 150,
    },
    {
      headerName: '原料编号',
      field: 'rawMaterialCode',
      width: 150,
    },
    {
      headerName: '原料名称',
      field: 'rawMaterialName',
      width: 150,
    },
    {
      headerName: '纱牌',
      field: 'brandName',
      width: 150,
    },
    {
      headerName: '纱批',
      field: 'yarnBatch',
      width: 150,
    },
    {
      headerName: '色号',
      field: 'colorCode',
      width: 150,
    },
    {
      headerName: '色称',
      field: 'colorName',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'level',
      width: 150,
    },
    {
      headerName: '可配色称',
      field: 'matchColor',
      width: 150,
    },
    {
      headerName: '领料-整件/件数',
      field: 'planMaterialPieceNum',
      width: 150,
    },
    {
      headerName: '整件/件重',
      field: 'planMaterialPieceWeight',
      width: 150,
    },
    {
      headerName: '整件/个数',
      field: 'pieceCount',
      width: 150,
    },
    {
      headerName: '领料-总重量',
      field: 'planMaterialWeight',
      width: 150,
    },
    {
      headerName: '未领料-总重量',
      field: 'unPlanMaterialWeight',
      width: 150,
      valueGetter: function (params: any) {
        return toFixedNum(params.data.planMaterialWeight - params.data.outStockWeight)
      },
    },
    {
      headerName: '已出库-整件/件数',
      field: 'outStockPieceNum',
      width: 150,
    },
    {
      headerName: '已出库-散件/件数',
      field: 'outStockBulkNumber',
      width: 150,
    },
    {
      headerName: '已出库-散件/散重',
      field: 'outStockBulkWeight',
      width: 150,
    },
    {
      headerName: '已出库-散件/个数',
      field: 'outStockBulkCount',
      width: 150,
    },
    {
      headerName: '已出库-总重量',
      field: 'outStockWeight',
      width: 150,
    },
    // {
    //   headerName: '未出库-整件/件数',
    //   field: 'unOutStockPieceNum',
    //   width: 150,
    //   valueGetter: (params: any) => {
    //     return toFixedNum(params.data.planMaterialPieceNum - params.data.outStockPieceNum)
    //   },
    // },
    {
      headerName: '库存-总重量',
      field: 'stockTotalWeight',
      width: 150,
    },

    {
      headerName: '库存-整件/件数',
      field: 'stockPieceNumber',
      width: 150,
    },
    {
      headerName: '库存-散件/件数',
      field: 'stockBulkNumber',
      width: 150,
    },
    {
      headerName: '库存-散件/散重',
      field: 'stockBulkWeight',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '备注',
      field: 'remark',
      width: 150,
    },
    {
      headerName: '加急件数',
      field: 'urgentCount',
      width: 120,
      pinned: 'right',
    },
    {
      headerName: '是否加急',
      field: 'urgentState',
      pinned: 'right',
      width: 120,
      cellRenderer: {
        template: `
            <a-button v-if="b == 0" status="success" size="mini">正常</a-button>
            <a-button v-if="b == 1" type="primary" status="danger" size="mini">加急</a-button>
            `,
        setup(props: any) {
          return {
            b: props.params.data.urgentState,
          }
        },
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '0' ? '正常' : params.value == '1' ? '加急' : ''
        },
      },
    },
    {
      headerName: '完结状态',
      field: 'useState',
      width: 120,
      pinned: 'right',
      cellRenderer: {
        template: `
            <a-button v-if="useState == 1" status="success" size="mini">已完结</a-button>
            <a-button v-if="useState == 0" type="primary" status="danger" size="mini">未完结</a-button>
            `,
        setup(props: any) {
          return {
            useState: props.params.data.useState,
          }
        },
      },
      filterParams: {
        valueFormatter: (params: any) => {
          return params.value == 1 ? '已完结' : '未完结'
        },
      },
    },
  ]

  const selectHandler = () => {
    if (tabsKeys.value == 1) {
      fySelet2.page = 1
      cxYcList()
    } else if (tabsKeys.value == 2) {
      fySelet.page = 1
      cxCgsList()
    } else if (tabsKeys.value == 3) {
      fySelet5.page = 1
      cxCgsList2()
    } else if (tabsKeys.value == 4) {
      fySelet4.page = 1
      cxCgsList3()
    } else if (tabsKeys.value == 5) {
      fySelet6.page = 1
      tkOutus()
    } else if (tabsKeys.value == 6) {
      fySelet8.page = 1
      OemList()
    }
  }
  onMounted(async() => {
    updateGridState01()
    updateGridState02()
    updateGridState03()
    updateGridState04()
    updateGridState05()
    updateGridState06()
    updateGridState07()
    await whChange()
    cxYcList()
  })
  const tabsKeys: any = ref(1)

  const tabsChanges = (e: any) => {
    tabsKeys.value = e
    if (e == 1) {
      toolbarList.value = [
        '打印',
        `${permissionStore.hasPermisson('yscck.yclcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('yscck.yclsh') ? '审核' : ''}`,
      ]
      cxYcList()
    } else if (e == 2) {
      toolbarList.value = [
        '调拨单申请',
        `${permissionStore.hasPermisson('yscck.llddclcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('yscck.llddclck') ? '出库' : ''}`,
      ]
      cxCgsList()
    } else if (e == 3) {
      toolbarList.value = [
        `${permissionStore.hasPermisson('yscck.dbddclcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('yscck.dbddclck') ? '出库' : ''}`,
      ]
      cxCgsList2()
    } else if (e == 4) {
      toolbarList.value = [
        `${permissionStore.hasPermisson('yscck.dbdyclcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('yscck.dbyclqxsh') ? '取消审核' : ''}`,
      ]
      cxCgsList3()
    } else if (e == 5) {
      toolbarList.value = ['查询', '新建出库单', '审核', '删除', '打印']
      tkOutus()
    } else if (e == 6) {
      toolbarList.value = ['查询', '审核', '删除']
      OemList()
    } else if (e == 7) {
      selectCx()
    }
  }

  const cgDcuList = reactive({
    pwDds: '',
    pwDds2: '',
  })
  let oneDayTime: any = ref([dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')])
  const cxCgsList = async () => {
    // isWlNameds,
    // isWlCodeds,
    if (pageDataLl.dateList.length == 0) {
      var startDate = ''
      var endDate = ''
    } else {
      var startDate = pageDataLl.dateList[0]
      var endDate = pageDataLl.dateList[1]
    }
    searchData.orderDate = dayjs(new Date()).format('YYYY-MM-DD')
    post({
      url: 'planSingle/planMaterial/getPlanMaterialListByWarehouse',
      data: {
        page: fySelet.page,
        size: fySelet.size,
        // firmId: pageData.a,
        // warehouseId: pageData.b,
        // rawmaterialCode: pageData.yarnCode,
        // rawmaterialName: pageData.yarnName,
        // brandName: pageData.yarnBrand,
        // yarnBatch: pageData.productionBatch,
        // level: pageData.level,

        useState: pageData.useState == '-1' ? undefined : pageData.useState,
        startDate: compareDate(startDate, endDate) == true ? endDate : startDate,
        endDate: compareDate(startDate, endDate) == true ? startDate : endDate,
        planOrderCode: pageDataLl.lingliaodanhao,
        rawmaterialCode: pageDataLl.yuanliaobianhao,
        rawmaterialName: pageDataLl.yuanliaomingc,
        customName: pageDataLl.kname,
        planMaterialCode: pageDataLl.lingliaodanhao,
        auditState: pageDataLl.auditState === '' ? undefined : pageDataLl.auditState,

        // firmName: pageData.c,
        // materialCode: pageData.d,
        // materialName: pageData.e,
      },
    }).then((res: any) => {
      gridOption2.value.setRowData(res.data.list)
      setTableTotalRow(gridOption2, res.data.list, [
        'planMaterialPieceNum',
        'planMaterialWeight',
        'unPlanMaterialWeight',
        'outStockPieceNum',
        'outStockBulkNumber',
        'outStockBulkWeight',
        'outStockBulkCount',
        'outStockWeight',
        'unOutStockPieceNum',
        'unOutStockWeight',
        'stockTotalWeight',
        'stockPieceNumber',
        'stockBulkNumber',
        'stockBulkWeight',
      ])
      tableDataList2.value = res.data.list
      fySelet.total = res.data.total
    })
  }
  const handleOutStockModalSearch = async () => {
    try {
      const valid = await drawerRef.value.validate()
      if (valid) return
      const ids = gridOptionRef2.value.getListData().map((item: any) => item.id)
      const res = await post({
        url: 'planSingle/planMaterial/getPlanMaterialListByWarehouseAndIds',
        data: {
          ids,
          warehouseId: drawerData.warehouseTypeId,
        },
      })
      if (res.code == 200) {
        const oldData = gridOptionRef2.value.getListData()
        const nowData = res.data
        const mergeData = []
        oldData.forEach((item: any) => {
          const newItem = nowData.find((item1: any) => item1.id === item.id)
          if (newItem) {
            newItem.pieceNumber = item.pieceNumber
            newItem.bulkWeight = item.bulkWeight
            newItem.bulkNumber = item.bulkNumber
            newItem.bulkCount = item.bulkCount
            newItem.weightTotal = item.weightTotal
            newItem.outStockType = '车间领料'
          }
        })
        gridOptionRef2.value.setdataListIterface(nowData)
      } else {
        Message.error(res.message)
      }
    } catch (error) {
      console.log(error)
    }
  }
  const cxYcList = () => {
    let startDate: string
    let endDate: string
    if (pageDataLl.dateList1.length == 0) {
      startDate = ''
      endDate = ''
    } else {
      startDate = pageDataLl.dateList1[0]
      endDate = pageDataLl.dateList1[1]
    }
    post({
      url: 'wms/yarnOutStock/getPage',
      data: {
        page: fySelet2.page,
        size: fySelet2.size,
        orderType:  "0,3",
        firmId: pageData.a,
        warehouseId: pageData.b,
        yarnCode: pageData.yarnCode,
        yarnName: pageData.yarnName,
        yarnBrand: pageData.yarnBrand,
        productionBatch: pageData.productionBatch,
        plan_material_code: pageData.plan_material_code,
        outStockTypeList:pageData.outStockTypes,
        out_stock_number: pageData.out_stock_number,
        level: pageData.level,
        startDate: compareDate(startDate, endDate) == true ? endDate : startDate,
        endDate: compareDate(startDate, endDate) == true ? startDate : endDate,
        auditState: pageData.auditState == 2 ? '' : pageData.auditState,
        // companyName:pageData.a,
        // warehouseName:pageData.b
      },
    }).then((res: any) => {
      gridOption.value.setRowData(res.data.list)
      setTableTotalRow(gridOption, res.data.list, [
        'pieceNumber',
        'bulkNumber',
        'bulkWeight',
        'bulkCount',
        'weightTotal',
      ])
      tableDataList.value = res.data.list
      fySelet2.total = res.data.total
    })
  }

  const cgRoutList: any = ref([])

  const redersOut = async () => {
    if (tabsKeys.value == 3) {
      if (gridOption3.value.getSelectedRows().length == 0) {
        Message.error('请选择调拨单号')
        return
      }
      let objListSet = new Set(
        gridOption3.value.getSelectedRows().map((res: any) => {
          return res.transferNumber
        })
      )
      if (objListSet.size > 1) {
        Message.error('请勾选相同调拨单')
        return
      }
      const { data, code, message } = await post({
        url: 'wms/yarnTransferStock/getListByTransferNumber',
        data: Array.from(objListSet),
      })
      if (code == 200) {
        cgData2.value = data
        cgData2.value.forEach((item: any) => {
          item.weightTotal1 = item.weightTotal
        })
        gridOptionRef3.value.setdataListIterface(cgData2.value)
        cgOut.visible2 = true
      } else {
        Message.error(message)
      }
    } else {
      let hasWJ = gridOption2.value.getSelectedRows().some(function (obj: any) {
        return obj.useState === 1
      })
      if (hasWJ) {
        Message.error('勾选中包含已完结数据！不可出库！')
        return
      }
      if (gridOption2.value.getSelectedRows().length == 0) {
        Message.error('请选择领料单号')
        return
      }
      const firstLineCompanyId = gridOption2.value.getSelectedRows()[0].companyId
      const isSelectSame = gridOption2.value
        .getSelectedRows()
        .every((item: any) => item.companyId === firstLineCompanyId)
      if (!isSelectSame) {
        Message.error('请选择相同公司的调拨单')
        return
      }
      for (let i = 0; i < gridOption2.value.getSelectedRows().length; i++) {
        for (let j = 1; j < gridOption2.value.getSelectedRows().length; j++) {
          if (
            gridOption2.value.getSelectedRows()[i].warehouseId !=
            gridOption2.value.getSelectedRows()[j].warehouseId
          ) {
            Message.error('请勾选相同仓库出库')
            return
          }
        }
      }
      const result = await getWarehouseList(firstLineCompanyId, '出库')
      post({
        url: 'wms/yarnOutStock/lockByPlanMaterialDetailId',
        data: gridOption2.value.getSelectedRows().map((res: any) => {
          return res.id
        }),
      }).then((rs: any) => {
        if (rs.code == 200) {
          post({
            url: 'wms/stockoutType/getStockoutTypePara',
            data: {
              warehouseId: gridOption2.value.getSelectedRows()[0].warehouseId,
              deleteState: 0,
            },
          })
            .then((res: any) => {
              if (res.code == 200) {
                outStockTypeList.value = res.data
                cgOut.visible = true
                const getselect = JSON.parse(JSON.stringify(gridOption2.value.getSelectedRows()))

                //默认勾选的第一条数据的仓库
                // drawerData.warehouseTypeId = getselect[0].warehouseId
                getselect.forEach((res: any) => {
                  res['supplier'] = res.supplierName
                  delete res.supplierName
                  res.pieceNumber = res.planMaterialPieceNum - res.outStockPieceNum
                  res.bulkWeight = 0
                  res.bulkNumber = 0
                  res.bulkCount = 0
                  res.weightTotal = res.pieceNumber * res.planMaterialPieceWeight
                  res.outStockType = '车间领料'
                })
                nextTick(() => {
                  setTimeout(function () {
                    gridOptionRef2.value.setdataListIterface(getselect)
                  }, 0)
                })
              } else {
                Message.error(res.message)
              }
            })
            .catch((err) => {
              Message.error('出库类型获取失败')
            })
        } else {
          Message.error(rs.message)
        }
      })
    }
  }

  let outStockTypeList = ref([])
  //查询出库类型
  function cxOutStockType(whID: any) {
    return new Promise(async (resolve: any, reject: any) => {
      try {
        const res = await post({
          url: 'wms/stockoutType/getStockoutTypePara',
          data: {
            warehouseId: whID,
            deleteState: 0,
          },
        })
        if (res.code == 200) {
          outStockTypeList.value = res.data
          resolve()
        }
      } catch (error) {
        console.log(error)
        reject()
      }
    })
  }

  const cgOut = reactive({
    visible: false,
    visible2: false,
    title: '领料单出库',
  })

  const cgHandleOk = async () => {
    console.log(drawerData.warehouseTypeId)
    if (!drawerData.warehouseTypeId) {
      Message.warning('请先选择仓库!')
      return false
    }
    const valid = await drawerRef.value.validate()
    if (valid) return false
    const warehouseObj: any = drawerData.warehouseList.find(
      (item: any) => item.id == drawerData.warehouseTypeId
    )
    const listData = JSON.parse(JSON.stringify(gridOptionRef2.value.getListData()))
    for(let i=0;i<listData.length;i++){
      let item=listData[i]
      if (!item.bulkNumber) {
        item.bulkNumber = 0
      }
      if (!item.bulkWeight) {
        item.bulkWeight = 0
      }
      if (!item.bulkCount) {
        item.bulkCount = 0
      }
      if (!item.pieceNumber) {
        item.pieceNumber = 0
      }

      if (item.bulkWeight > 0) {
        if (item.bulkNumber > 0 && item.bulkCount > 0) {
          
        } else {
          Message.warning('请确认散件/件数，散件/个数，散件/件重 字段是否有误!')
          break 
        }
      }

      if (item.bulkNumber > 0) {
        if (item.bulkWeight > 0 && item.bulkCount > 0) {
          
        } else {
          Message.warning('请确认散件/件数，散件/个数，散件/件重 字段是否有误!')
          break 
        }
      }

      if (item.bulkCount > 0) {
        if (item.bulkNumber > 0 && item.bulkWeight > 0) {
          console.log(111)
        } else {
          Message.warning('请确认散件/件数，散件/件重 字段是否有误!')
          break 
        }
      }

      //出库的散件件重和散件件数有一个等于库存，另一个不等于库存则提示有误
      if (
          item.stockBulkNumber==item.bulkNumber&&item.bulkWeight!==item.stockBulkWeight||
          item.stockBulkNumber!==item.bulkNumber&&item.bulkWeight==item.stockBulkWeight
          ) {
            Message.warning('请确认散件/件数，散件/件重 字段是否有误!')
            break 
            }
      if (item.weightTotal == 0) {
        Message.warning('出库总重量不能为0!')
        break 
      }

     
      item['planMaterialDetailId'] = item.id
      item['outStockNumber'] = item.orderNo
      item['firmId'] = item.companyId
      item['firm'] = item.company
      item['warehouse'] = warehouseObj ? warehouseObj.warehouseName : ''
      item['warehouseId'] = drawerData.warehouseTypeId
      item['warehouseName'] = warehouseObj ? warehouseObj.warehouseName : ''
      item['yarnId'] = item.yarnId
      item['yarnCode'] = item.rawMaterialCode
      item['yarnName'] = item.rawMaterialName
      item['yarnBrand'] = item.brandName
      item['productionBatch'] = item.yarnBatch
      item['pieceWeight'] = item.planMaterialPieceWeight
      item['level'] = item.level
      item['matchColor'] = item.matchColor
      item['orderType'] = 0
    }
    // listData.forEach((item: any) => {
     
    // })
    const { code, message } = await post({
      url: 'wms/yarnOutStock/stockOutByPlanMaterial',
      data: listData,
    })
    if (code == 200) {
      cxYcList()
      cxCgsList()
      post({
        url: 'wms/yarnOutStock/releaseLockByPlanMaterialDetailId',
      })
      Message.success('成功')
      return true
    }
    Message.error(message)
    return false
  }
  const warehouseChange = ($event: any, record: any) => {
    if ($event != '' || $event != undefined) {
      record['warehouseId'] = Number($event.split('-')[0])
      record['warehouseName'] = $event.split('-')[1]
      return
    }
  }

  const cadelvs = () => {
    post({
      url: 'wms/yarnOutStock/releaseLockByPlanMaterialDetailId',
    })
    cgData.value = []
    drawerData.warehouseTypeId = ''
    cgOut.visible = false
  }

  const delSles = () => {
    // Modal.confirm({
    //     title: '系统提示',
    //     content: '确认删除选中的数据?',
    //     onOk: () => {
    //         post({
    //             url: 'wms/ironwareOutStock/delete',
    //             data: gridOption.value.getSelectedRows().map((res: any) => res.id)
    //         }).then((res: any) => {
    //             if (res.code == 200) {
    //                 Message.success('删除成功')
    //                 cxYcList()
    //             } else (
    //                 Message.error(res.message)
    //             )
    //         })
    //     },
    // })
    if (tabsKeys.value == 5) {
      if (gridOption6.value.getSelectedRows().length == 0) {
        Message.error('请勾选数据')
        return false
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认删除选中的数据?',
        onOk: () => {
          post({
            url: 'wms/yarnOutStock/deleteByIds',
            data: gridOption6.value.getSelectedRows().map((res: any) => {
              return res.id
            }),
          }).then((res: any) => {
            if (res.code == 200) {
              Message.success('成功')
              tkOutus()
            } else Message.error(res.message)
          })
        },
      })
    } else if (tabsKeys.value == 6) {
      if (gridOption8.value.getSelectedRows().length == 0) {
        Message.error('请勾选数据')
        return false
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认删除选中的数据?',
        onOk: () => {
          post({
            url: 'wms/yarnOutStock/deleteByIds',
            data: gridOption8.value.getSelectedRows().map((res: any) => {
              return res.id
            }),
          }).then((res: any) => {
            if (res.code == 200) {
              Message.success('成功')
              OemList()
            } else Message.error(res.message)
          })
        },
      })
    }
  }

  const audits = () => {
    if (tabsKeys.value == 1) {
      if (gridOption.value.getSelectedRows().length == 0) {
        Message.error('请勾选数据')
        return false
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认审核选中的数据?',
        onOk: () => {
          post({
            url: 'wms/yarnOutStock/stockOutOnAuditState',
            data: gridOption.value.getSelectedRows().map((res: any) => {
              return res.id
            }),
          }).then((res: any) => {
            if (res.code == 200) {
              Message.success('成功')
              cxYcList()
            } else Message.error(res.message)
          })
        },
      })
    }
    if (tabsKeys.value == 5) {
      if (gridOption6.value.getSelectedRows().length == 0) {
        Message.error('请勾选数据')
        return false
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认审核选中的数据?',
        onOk: () => {
          post({
            url: 'wms/yarnOutStock/stockOutOnAuditStateByReturn',
            data: gridOption6.value.getSelectedRows().map((res: any) => {
              return res.id
            }),
          }).then((res: any) => {
            if (res.code == 200) {
              Message.success('成功')
              tkOutus()
            } else Message.error(res.message)
          })
        },
      })
    }
    if (tabsKeys.value == 6) {
      if (gridOption8.value.getSelectedRows().length == 0) {
        Message.error('请勾选数据')
        return false
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认审核选中的数据?',
        onOk: () => {
          post({
            url: 'wms/yarnOutStock/stockOutOnAuditStateByReturn',
            data: gridOption8.value.getSelectedRows().map((res: any) => {
              return res.id
            }),
          }).then((res: any) => {
            if (res.code == 200) {
              Message.success('成功')
              OemList()
            } else Message.error(res.message)
          })
        },
      })
    }
  }

  const cgData: any = ref([])

  const adddbs = () => {
    dbPageDate.showAdd = true
  }

  const dbPageDate = reactive({
    showAdd: false,
    titles: '新建调拨单',
  })

  const formRef = ref()

  const sideOk = async () => {
    if (wlListArray.value.length == 0) {
      Message.warning({
        content: '请新增至少一条原料信息',
        duration: 5000,
      })
      return
    }
    formRef.value?.validate().then((err: any) => {
      if (!err) {
        wlListArray.value.forEach((item: any) => {
          item['outFirmId'] = searchData.fhFirmId
          item['outFirm'] = searchData.fhFirm
          item['inFirmId'] = searchData.shFirmId
          item['inFirm'] = searchData.shFirm
          item['outWarehouseId'] = Number(searchData.fhWh.split('-')[0])
          item['outWarehouse'] = searchData.fhWh.split('-')[1]
          item['inWarehouseId'] = Number(searchData.shWh.split('-')[0])
          item['inWarehouse'] = searchData.shWh.split('-')[1]
          delete item['id']
        })
        post({
          url: 'wms/yarnTransferStock/insertList',
          data: wlListArray.value,
        }).then(({ code, message }) => {
          if (code == 200) {
            cxYcList()
            cxCgsList()
            cxCgsList2()
            Message.success('成功')
            for (let i in searchData) {
              searchData[i] = ''
            }
            wlListArray.value = []
            dbPageDate.showAdd = false
          } else {
            Message.error(message)
          }
        })
      }
    })
  }

  const sideNo = () => {
    for (let i in searchData) {
      searchData[i] = ''
    }
    wlListArray.value = []
    dbPageDate.showAdd = false
  }

  const searchData: any = reactive({
    fhFirm: '',
    fhFirmId: null,
    fhWh: '',
    shFirm: '',
    shFirmId: null,
    shWhType: '',
    shWh: '',
    warehouseId: null,
    warehouseName: '',
    warehouseList: [],
  })

  const configCascader = ref<{}>({
    corporateWidth: '15rem', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: true, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '发货公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const configCascader2 = ref<{}>({
    corporateWidth: '15rem', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: true, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '收货公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const configCascader4 = ref<{}>({
    corporateWidth: '15rem', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: true, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '申请公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const whService = new WHService()
  const fhWhList: any = whService.whList
  const changeCascader = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    searchData.fhWh = ''
    searchData.fhFirmId = corporateId
    searchData.fhFirm = corporateLabel
    searchData.warehouseId = ''
    searchData.firmId = corporateId
    whService.getWarhouseListByFirmId(corporateId, '原纱仓')
  }

  const whService2 = new WHService()
  const shWhList: any = whService2.whList
  const changeCascader2 = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    searchData.shWh = ''
    searchData.shFirmId = corporateId
    searchData.shFirm = corporateLabel
    whService2.getWarhouseListByFirmId(corporateId, '原纱仓')
  }
  const whTypeList: any = ref([])

  const whService3 = new WHService()
  const shWhList3: any = whService3.whList
  const configCascader3 = ref<{}>({
    corporateWidth: '200px', //公司宽度
    corporateNameLabelWidth: '70px',
    sectorWidth: '180px', //部门宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'small', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '选择公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const changeCascader3 = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    pageData.b = ''
    pageData.a = corporateId
    whService3.getWarhouseListByFirmId(corporateId, '原纱仓')
  }

  const wlListArray: any = ref([])

  const tableColumnsWl: any = [
    {
      dataIndex: 'firm',
      key: 'firm',
      title: '公司',
      width: 150,
    },
    {
      dataIndex: 'warehouse',
      key: 'warehouse',
      title: '仓库',
      width: 150,
    },
    {
      dataIndex: 'inStockType',
      key: 'inStockType',
      slotName: 'inStockType',
      title: '入库类型',
      width: 150,
    },
    {
      dataIndex: 'supplier',
      key: 'supplier',
      slotName: 'supplier',
      title: '供应商名称',
      width: 150,
    },
    {
      dataIndex: 'customName',
      key: 'customName',
      slotName: 'customName',
      title: '客户名称 ',
      width: 150,
    },
    {
      dataIndex: 'yarnCode',
      key: 'yarnCode',
      title: '原料编号',
      width: 150,
    },
    {
      dataIndex: 'yarnName',
      key: 'yarnName',
      title: '纱线名称',
      width: 150,
    },
    {
      dataIndex: 'yarnBrand',
      key: 'yarnBrand',
      title: '纱牌',
      width: 150,
    },
    {
      dataIndex: 'productionBatch',
      key: 'productionBatch',
      title: '纱批',
      width: 150,
    },
    {
      dataIndex: 'level',
      key: 'level',
      slotName: 'level',
      title: '等级',
      width: 150,
    },
    {
      dataIndex: 'matchColor',
      key: 'matchColor',
      title: '可配色称',
      slotName: 'matchColor',
      width: 150,
    },
    {
      dataIndex: 'colorCode',
      key: 'colorCode',
      slotName: 'colorCode',
      title: '色号',
      // fixed: 'right',
      width: 150,
    },
    {
      dataIndex: 'colorName',
      key: 'colorName',
      slotName: 'colorName',
      title: '色称',
      width: 150,
    },
    {
      dataIndex: 'pieceNumber',
      key: 'pieceNumber',
      title: '整件/件数',
      slotName: 'pieceNumber',
      width: 150,
    },
    {
      dataIndex: 'pieceWeight',
      key: 'pieceWeight',
      title: '整件/件重',
      width: 150,
    },
    {
      dataIndex: 'bulkNumber',
      key: 'bulkNumber',
      title: '散件/件数',
      slotName: 'bulkNumber',
      width: 150,
    },
    {
      dataIndex: 'bulkWeight',
      key: 'bulkWeight',
      title: '散件/散重',
      slotName: 'bulkWeight',
      width: 150,
    },
    {
      dataIndex: 'weightTotal',
      key: 'weightTotal',
      title: '总重量',
      width: 150,
    },
    {
      dataIndex: 'packingFeature',
      key: 'packingFeature',
      title: '包装特征',
      slotName: 'packingFeature',
      width: 150,
    },
    {
      dataIndex: 'unit',
      key: 'unit',
      title: '单位',
      slotName: 'unit',
      width: 150,
    },
    {
      dataIndex: 'location',
      key: 'location',
      slotName: 'location',
      title: '库位',
      width: 150,
    },
    {
      dataIndex: 'remark',
      key: 'remark',
      slotName: 'remark',
      title: '备注',
      width: 150,
    },
  ]
  let typeIds = 0
  const addLine = () => {
    if (searchData.fhWh == '' || searchData.fhFirm == '') {
      Message.error('请先选择发货公司仓库')
      return
    }
    dbSelect()
    visibleYl.value = true
  }

  const dbSelect = () => {
    post({
      url: 'wms/yarnInStock/getPage',
      data: {
        page: 1,
        size: fySelet2.size,
        firm_id: searchData.fhFirmId,
        warehouse_id: Number(searchData.fhWh.split('-')[0]),
      },
    }).then((res: any) => {
      wlListXqs.value = res.data.list
      fySelet3.total = res.data.total
    })
  }

  const selectedRowKeysWl: any = ref([])

  const delLine = () => {
    if (selectedRowKeysWl.value.length === 0) {
      Message.error({
        content: '请先勾选',
        duration: 5000,
      })
      return
    }

    wlListArray.value = wlListArray.value.filter(function (o: any) {
      return selectedRowKeysWl.value.indexOf(o['typeIds']) === -1
    })
  }

  const wlPageDatas: any = reactive({
    wlListL: [],
    wlListS: [],
    wlList: [],
  })

  const focusSel = () => {
    post({
      url: 'purchase/MaterialBigClass/getFieldValue',
      data: { bigClassName: '', deleteState: 0 },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        wlPageDatas.wlListL = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }
  const focusSel1 = () => {
    post({
      url: 'purchase/MaterialSubClass/getFieldValue',
      data: { bigClassName: '' },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        wlPageDatas.wlListS = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }
  const focusSel2 = (record: any) => {
    post({
      url: 'purchase/MaterialInfo/getFieldValueWms',
      data: { subClassName: record.subCategory, materialName: '' },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        wlPageDatas.wlList = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }

  const changeWl = (record: any, val: any) => {
    let list2 = wlListArray.value.filter(function (o: any) {
      return o['materialName'] == record['materialName']
    })
    if (list2.length > 1) {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['specification'] = ''
      Message.warning({
        content: '请不要重复选择物料！',
        duration: 5000,
      })
      return
    }
    let list = wlPageDatas.wlList.filter(function (o: any) {
      return o['materialName'] == val
    })
    if (list.length > 0) {
      record['materialCode'] = list[0]['materialCode']
      record['unit'] = list[0]['unit']
      record['specification'] = list[0]['specification']
    }
  }
  const qkChanges = (record: any) => {
    record['materialCode'] = ''
    record['unit'] = ''
    record['materialName'] = ''
  }

  const gradrList: any = ref([])

  const gradeChange = () => {
    post({
      url: 'dict/dictTypeDetail/getListByMap',
      data: {
        codeType: 36,
        detailName: '',
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        gradrList.value = data
      }
    })
  }

  const visibleYl = ref(false)

  const selectedRowKeys2 = ref([])

  const wlListXqs: any = ref([])

  const tableColumns3: any = [
    {
      dataIndex: 'firm',
      key: 'firm',
      title: '公司',
      width: 150,
    },
    {
      dataIndex: 'warehouse',
      key: 'warehouse',
      title: '仓库',
      width: 150,
    },
    {
      dataIndex: 'inStockType',
      key: 'inStockType',
      slotName: 'inStockType',
      title: '入库类型',
      width: 150,
    },
    {
      dataIndex: 'supplier',
      key: 'supplier',
      slotName: 'supplier',
      title: '供应商名称',
      width: 150,
    },
    {
      dataIndex: 'customName',
      key: 'customName',
      slotName: 'customName',
      title: '客户名称 ',
      width: 150,
    },
    {
      dataIndex: 'yarnCode',
      key: 'yarnCode',
      title: '原料编号',
      width: 150,
    },
    {
      dataIndex: 'yarnName',
      key: 'yarnName',
      title: '纱线名称',
      width: 150,
    },
    {
      dataIndex: 'yarnBrand',
      key: 'yarnBrand',
      title: '纱牌',
      width: 150,
    },
    {
      dataIndex: 'productionBatch',
      key: 'productionBatch',
      title: '纱批',
      width: 150,
    },
    {
      dataIndex: 'level',
      key: 'level',
      slotName: 'level',
      title: '等级',
      width: 150,
    },
    {
      dataIndex: 'matchColor',
      key: 'matchColor',
      title: '可配色称',
      slotName: 'matchColor',
      width: 150,
    },
    {
      dataIndex: 'colorCode',
      key: 'colorCode',
      slotName: 'colorCode',
      title: '色号',
      // fixed: 'right',
      width: 150,
    },
    {
      dataIndex: 'colorName',
      key: 'colorName',
      slotName: 'colorName',
      title: '色称',
      width: 150,
    },
    {
      dataIndex: 'pieceNumber',
      key: 'pieceNumber',
      title: '整件/件数',
      slotName: 'pieceNumber',
      width: 150,
    },
    {
      dataIndex: 'pieceWeight',
      key: 'pieceWeight',
      title: '整件/件重',
      width: 150,
    },
    {
      dataIndex: 'bulkNumber',
      key: 'bulkNumber',
      title: '散件/件数',
      slotName: 'bulkNumber',
      width: 150,
    },
    {
      dataIndex: 'bulkWeight',
      key: 'bulkWeight',
      title: '散件/散重',
      slotName: 'bulkWeight',
      width: 150,
    },
    {
      dataIndex: 'weightTotal',
      key: 'weightTotal',
      title: '总重量',
      width: 150,
    },
    {
      dataIndex: 'packingFeature',
      key: 'packingFeature',
      title: '包装特征',
      slotName: 'packingFeature',
      width: 150,
    },
    {
      dataIndex: 'unit',
      key: 'unit',
      title: '单位',
      slotName: 'unit',
      width: 150,
    },
    {
      dataIndex: 'location',
      key: 'location',
      slotName: 'location',
      title: '库位',
      width: 150,
    },
    {
      dataIndex: 'remark',
      key: 'remark',
      slotName: 'remark',
      title: '备注',
      width: 150,
    },
  ]

  const handleOks = () => {
    if (selectedRowKeys2.value.length == 0) {
      Message.error('请勾选数据')
      return false
    }
    let islistArray: any = []
    selectedRowKeys2.value.forEach((v: any) => {
      wlListXqs.value.forEach((o: any) => {
        if (v == o.id) {
          islistArray.push(o)
        }
      })
    })
    wlListArray.value = islistArray
    wlListArray.value.forEach((o: any) => {
      o['a'] = o.pieceNumberjiHUsn3
      o['b'] = o.bulkNumber
      o['c'] = o.bulkWeight
    })
    wlListXqs.value = []
    selectedRowKeys2.value = []
    visibleYl.value = false
    return true
  }
  const handleCancels = () => {
    wlListXqs.value = []
    selectedRowKeys2.value = []
    visibleYl.value = false
  }

  const jiHUsn = (e: any) => {
    if (e.pieceNumber == undefined) {
      e.pieceNumber = 0
    }
    if (e.pieceWeight == undefined) {
      e.pieceWeight = 0
    }
    if (e.bulkWeight == undefined) {
      e.bulkWeight = 0
    }
    if (e.bulkWeight) {
      e['weightTotal'] = Number((e.pieceNumber * e.pieceWeight + e.bulkWeight).toFixed(2))
      if (e.pieceWeight && e.pieceNumber != undefined) {
        e['weightTotal'] = Number((e.pieceNumber * e.pieceWeight).toFixed(2))
      } else {
        e['weightTotal'] = 0
      }
    }
  }

  const jiHUsn2 = (e: any) => {
    if (e.pieceNumber == undefined) {
      e.pieceNumber = 0
    }
    if (e.pieceWeight == undefined) {
      e.pieceWeight = 0
    }
    if (e.bulkWeight == undefined) {
      e.bulkWeight = 0
    }
    if (e.bulkWeight) {
      e['weightTotal'] = Number((e.pieceNumber * e.pieceWeight + e.bulkWeight).toFixed(2))
    } else {
      e['weightTotal'] = Number((e.pieceNumber * e.pieceWeight).toFixed(2))
    }
  }

  const jiHUsn3 = (e: any) => {
    if (e.pieceNumber == undefined) {
      e.pieceNumber = 0
    }
    if (e.pieceWeight == undefined) {
      e.pieceWeight = 0
    }
    if (e.bulkWeight == undefined) {
      e.bulkWeight = 0
    }
    if (e.bulkWeight) {
      e['weightTotal'] = Number((e.pieceNumber * e.pieceWeight + e.bulkWeight).toFixed(2))
    } else {
      if (e.pieceNumber && e.pieceWeight) {
        e['weightTotal'] = Number((e.pieceNumber * e.pieceWeight).toFixed(2))
      }
    }
  }

  const jiHUsn4 = (e: any) => {
    if (e.bulkWeight) {
      e['weightTotal'] = Number((e.pieceNumber * e.pieceWeight + e.bulkWeight).toFixed(2))
    } else {
      if (e.pieceNumber && e.pieceWeight != undefined) {
        e['weightTotal'] = Number((e.pieceNumber * e.pieceWeight).toFixed(2))
      } else {
        e['weightTotal'] = 0
      }
    }
  }
  const fySelet3: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize3 = (val: any) => {
    fySelet.page = val
    cxCgsList()
  }

  const change3 = (val: any) => {
    fySelet.size = val
    cxCgsList()
  }

  const fySelet5: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize5 = (val: any) => {
    fySelet5.page = val
    cxCgsList2()
  }

  const change5 = (val: any) => {
    fySelet5.size = val
    cxCgsList2()
  }

  const fySelet7: any = reactive({
    total: 0,
    size: 10,
    page: 1,
  })

  const PageSize7 = (val: any) => {
    fySelet7.page = val
    cxCgsLists()
  }

  const change7 = (val: any) => {
    fySelet7.size = val
    cxCgsLists()
  }
  const tableDataList3 = ref([])
  const defaultColDef3 = {
    sortable: true,
    resizable: true,
    filter: true,
  }
  const gridOption3 = ref()
  const colState4 = ref()
  const gridReady3 = (params: any) => {
    gridOption3.value = params.api
    colState4.value = params.columnApi
  }
  const tableDataList5 = ref([])
  const gridOption5 = ref()
  const colState5 = ref()
  const gridReady5 = (params: any) => {
    gridOption5.value = params.api
    colState5.value = params.columnApi
  }

  const tableDataList6 = ref([])
  const gridOption6 = ref()
  const colState6 = ref()
  const gridReady6 = (params: any) => {
    gridOption6.value = params.api
    colState6.value = params.columnApi
  }

  const tableDataList8 = ref([])
  const gridOption8 = ref()
  const colState8 = ref()
  const gridReady8 = (params: any) => {
    gridOption8.value = params.api
    colState8.value = params.columnApi
  }
  const tc6 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    // {
    //     headerName: '类型',
    //     field: 'infoType',
    //     width: 150,
    //     cellRenderer: {
    //         template: `<span>{{states==1?'领料出库':states==2?'调拨出库':''}}</span>`,
    //         setup(props: any) {
    //             return {
    //                 states: props.params.data.infoType
    //             }
    //         }
    //     }
    // },
    {
      headerName: '出库单号',
      field: 'outStockNumber',
      width: 150,
    },
    {
      headerName: '公司',
      field: 'firm',
      width: 150,
    },
    {
      headerName: '仓库',
      field: 'warehouse',
      width: 150,
    },
    {
      headerName: '出库类型',
      field: 'outStockType',
      width: 150,
    },
    {
      headerName: '搬运计件',
      field: 'transportName',
      width: 150,
    },
    {
      headerName: '供应商名称',
      field: 'supplier',
      width: 150,
    },
    {
      headerName: '客户名称',
      field: 'customName',
      width: 150,
    },
    {
      headerName: '原料编号',
      field: 'yarnCode',
      width: 150,
    },
    {
      headerName: '原料名称',
      field: 'yarnName',
      width: 150,
    },
    {
      headerName: '纱牌',
      field: 'yarnBrand',
      width: 150,
    },
    {
      headerName: '纱批',
      field: 'productionBatch',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'level',
      width: 150,
    },
    {
      headerName: '可配色称',
      field: 'matchColor',
      width: 150,
    },
    {
      headerName: '色号',
      field: 'colorCode',
      width: 150,
    },
    {
      headerName: '色称',
      field: 'colorName',
      width: 150,
    },
    {
      headerName: '整件/件数',
      field: 'pieceNumber',
      width: 150,
    },
    {
      headerName: '整件/件重',
      field: 'pieceWeight',
      width: 150,
    },
    {
      headerName: '整件/个数',
      field: 'pieceCount',
      width: 150,
    },
    {
      headerName: '散件/件数',
      field: 'bulkNumber',
      width: 150,
    },
    {
      headerName: '散件/散重',
      field: 'bulkWeight',
      width: 150,
    },
    {
      headerName: '散件/个数',
      field: 'bulkCount',
      width: 150,
    },

    {
      headerName: '总数量',
      field: 'weightTotal',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '备注',
      field: 'remark',
      width: 150,
    },
    {
      headerName: '开单人',
      field: 'createName',
      width: 150,
    },
    {
      headerName: '开单日期',
      field: 'createDate',
      width: 150,
    },
    {
      headerName: '审核人员',
      field: 'auditName',
      width: 150,
    },
    {
      headerName: '审核日期',
      field: 'auditDate',
      width: 150,
    },
    {
      headerName: '审核状态',
      field: 'auditState',
      pinned: 'right',
      width: 150,
      cellRenderer: {
        template: `
            <a-button v-if="states == 1" status="success">已审核出库</a-button>
            <a-button v-else="states == 0" type="dashed" status="success">未审核</a-button>
            `,
        setup(props: any) {
          return {
            states: props.params.data.auditState,
          }
        },
      },
      cellStyle: (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '0' ? '未审核' : params.value == '1' ? '已审核出库' : ''
        },
      },
    },
  ]
  const tc7 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '出库单号',
      field: 'outStockNumber',
      width: 150,
    },
    {
      headerName: '公司',
      field: 'firm',
      width: 150,
    },
    {
      headerName: '仓库',
      field: 'warehouse',
      width: 150,
    },
    {
      headerName: '出库类型',
      field: 'outStockType',
      width: 150,
    },
    {
      headerName: '搬运计件',
      field: 'transportName',
      width: 150,
    },
    {
      headerName: '供应商名称',
      field: 'supplier',
      width: 150,
    },
    {
      headerName: '客户名称',
      field: 'customName',
      width: 150,
    },
    {
      headerName: '原料编号',
      field: 'yarnCode',
      width: 150,
    },
    {
      headerName: '原料名称',
      field: 'yarnName',
      width: 150,
    },
    {
      headerName: '纱牌',
      field: 'yarnBrand',
      width: 150,
    },
    {
      headerName: '纱批',
      field: 'productionBatch',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'level',
      width: 150,
    },
    {
      headerName: '色号',
      field: 'colorCode',
      width: 150,
    },
    {
      headerName: '色称',
      field: 'colorName',
      width: 150,
    },
    {
      headerName: '整件/件数',
      field: 'pieceNumber',
      width: 150,
    },
    {
      headerName: '整件/件重',
      field: 'pieceWeight',
      width: 150,
    },
    {
      headerName: '整件/个数',
      field: 'pieceCount',
      width: 150,
    },
    {
      headerName: '散件/件数',
      field: 'bulkNumber',
      width: 150,
    },
    {
      headerName: '散件/散重',
      field: 'bulkWeight',
      width: 150,
    },
    {
      headerName: '散件/个数',
      field: 'bulkCount',
      width: 150,
    },

    {
      headerName: '总数量',
      field: 'weightTotal',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '备注',
      field: 'remark',
      width: 150,
    },
    {
      headerName: '开单人',
      field: 'createName',
      width: 150,
    },
    {
      headerName: '开单日期',
      field: 'createDate',
      width: 150,
    },
    {
      headerName: '审核人员',
      field: 'auditName',
      width: 150,
    },
    {
      headerName: '审核日期',
      field: 'auditDate',
      width: 150,
    },
    {
      headerName: '审核状态',
      field: 'auditState',
      pinned: 'right',
      width: 150,
      cellRenderer: {
        template: `
            <a-button v-if="states == 1" status="success">已审核出库</a-button>
            <a-button v-else="states == 0" type="dashed" status="success">未审核</a-button>
            `,
        setup(props: any) {
          return {
            states: props.params.data.auditState,
          }
        },
      },
      cellStyle: (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '0' ? '未审核' : params.value == '1' ? '已审核出库' : ''
        },
      },
    },
  ]

  const tc3 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '调拨单号',
      field: 'transferNumber',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '转出公司',
      field: 'outFirm',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '转出仓库',
      field: 'outWarehouse',
      width: 150,
    },
    {
      headerName: '收货公司',
      field: 'inFirm',
      width: 150,
    },
    {
      headerName: '收货仓库',
      field: 'inWarehouse',
      width: 150,
    },
    {
      headerName: '来源单号',
      field: 'sourceNumber',
      width: 150,
    },
    {
      headerName: '贸易商',
      field: 'trader',
      width: 150,
    },
    {
      headerName: '库存组织',
      field: 'inventoryOrganization',
      width: 150,
    },

    {
      headerName: '客户名称',
      field: 'customName',
      width: 150,
    },
    {
      headerName: '原料编号',
      field: 'yarnCode',
      width: 150,
    },
    {
      headerName: '原料名称',
      field: 'yarnName',
      width: 150,
    },
    {
      headerName: '纱牌',
      field: 'yarnBrand',
      width: 150,
    },
    {
      headerName: '纱批',
      field: 'productionBatch',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'level',
      width: 150,
    },
    {
      headerName: '可配色称',
      field: 'matchColor',
      width: 150,
    },
    {
      headerName: '色号',
      field: 'colorCode',
      width: 150,
    },
    {
      headerName: '色称',
      field: 'colorName',
      width: 150,
    },
    {
      headerName: '整件/件数',
      field: 'pieceNumber',
      width: 150,
    },
    {
      headerName: '整件/件重',
      field: 'pieceWeight',
      width: 150,
    },
    {
      headerName: '散件/件数',
      field: 'bulkNumber',
      width: 150,
    },
    {
      headerName: '散件/散重',
      field: 'bulkWeight',
      width: 150,
    },
    {
      headerName: '总数量',
      field: 'weightTotal',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '纸骨',
      field: 'paperBone',
      width: 150,
    },
    {
      headerName: '库位',
      field: 'location',
      width: 150,
    },
    {
      headerName: '出库时间',
      field: 'outDate',
      width: 150,
    },
    {
      headerName: '出库人',
      field: 'outName',
      width: 150,
    },
    {
      headerName: '收货时间',
      field: 'inDate',
      width: 150,
    },
    {
      headerName: '收货人',
      field: 'inName',
      width: 150,
    },
    {
      headerName: '创单人',
      field: 'createName',
      width: 150,
    },
    {
      headerName: '创单时间',
      field: 'createDate',
      width: 150,
    },
    {
      headerName: '单据备注',
      field: 'remark',
      width: 150,
    },
    {
      headerName: '明细备注',
      field: 'detailRemake',
      width: 150,
    },
    {
      headerName: '单据类型',
      field: 'orderType',
      width: 120,
      pinned: 'right',
      cellRenderer: {
        template: `<a-space>
                <a-tag color="#f53f3f" style="position:relative;left:6px" v-if="infoState==0">普通调拨</a-tag>
                <a-tag style="position:relative;left:6px" color="green" v-if="infoState==1">加工出库单</a-tag>
                <a-tag style="position:relative;left:6px" color="green" v-if="infoState==2">加工领料单</a-tag>
                <a-tag style="position:relative;left:6px" color="green" v-if="infoState==3">加工收货单</a-tag>
                <a-tag style="position:relative;left:6px" color="green" v-if="infoState==4">纱线转让单</a-tag>
                <a-tag style="position:relative;left:6px" color="green" v-if="infoState==5">采购退货单</a-tag>
                </a-space>
            `,
        setup(props: any) {
          // const a = () => {
          //     rouWh(props.params.data)
          // }
          return {
            // a,
            infoState: props.params.data.orderType,
          }
        },
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '0'
            ? '普通调拨'
            : params.value == '1'
            ? '加工出库单'
            : params.value == '2'
            ? '加工领料单'
            : params.value == '3'
            ? '加工收货单'
            : params.value == '4'
            ? '纱线转让单'
            : params.value == '5'
            ? '采购退货单'
            : ''
        },
      },
    },
    {
      headerName: '单据状态',
      field: 'infoState',
      width: 110,
      pinned: 'right',
      cellRenderer: {
        template: `<a-space>
                <a-tag color="#f53f3f" style="position:relative;left:6px" v-if="infoState==0">未审核</a-tag>
                <a-tag style="position:relative;left:6px" color="green" v-if="infoState==1">已出库</a-tag>
                <a-tag style="position:relative;left:6px" color="green" v-if="infoState==2">已收货</a-tag>
                </a-space>
            `,
        setup(props: any) {
          // const a = () => {
          //     rouWh(props.params.data)
          // }
          return {
            // a,
            infoState: props.params.data.infoState,
          }
        },
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '0'
            ? '未审核'
            : params.value == '1'
            ? '已出库'
            : params.value == '2'
            ? '已收货'
            : ''
        },
      },
    },
  ]
  const cxCgsList2 = () => {
    let startDate: string
    let endDate: string
    if (pageDataLl.dateList1.length == 0) {
      startDate = ''
      endDate = ''
    } else {
      startDate = pageDataLl.dateList1[0]
      endDate = pageDataLl.dateList1[1]
    }
    post({
      url: 'wms/yarnTransferStock/getPage',
      data: {
        page: fySelet5.page,
        size: fySelet5.size,
        queryType: '0',
        infoState: 0,
        outFirmId: pageData.a,
        outWarehouseId: pageData.b,
        yarnCode: pageData.yarnCode,
        yarnName: pageData.yarnName,
        yarnBrand: pageData.yarnBrand,
        productionBatch: pageData.productionBatch,
        level: pageData.level,
        orderType: pageData.orderType ? pageData.orderType : null,
        startDate: compareDate(startDate, endDate) == true ? endDate : startDate,
        endDate: compareDate(startDate, endDate) == true ? startDate : endDate,
      },
    }).then((res: any) => {
      gridOption3.value.setRowData(res.data.list)
      setTableTotalRow(gridOption3, res.data.list, [
        'pieceNumber',
        'bulkNumber',
        'bulkWeight',
        'weightTotal',
      ])
      tableDataList3.value = res.data.list
      fySelet5.total = res.data.total
    })
  }

  const cxCgsList3 = () => {
    let startDate: string
    let endDate: string
    if (pageDataLl.dateList1.length == 0) {
      startDate = ''
      endDate = ''
    } else {
      startDate = pageDataLl.dateList1[0]
      endDate = pageDataLl.dateList1[1]
    }
    post({
      url: 'wms/yarnTransferStock/getPage',
      data: {
        page: fySelet4.page,
        size: fySelet4.size,
        queryType: '0',
        infoState: 1,
        outFirmId: pageData.a,
        outWarehouseId: pageData.b,
        yarnCode: pageData.yarnCode,
        yarnName: pageData.yarnName,
        yarnBrand: pageData.yarnBrand,
        productionBatch: pageData.productionBatch,
        level: pageData.level,
        orderType: pageData.orderType ? pageData.orderType : null,
        startDate: compareDate(startDate, endDate) == true ? endDate : startDate,
        endDate: compareDate(startDate, endDate) == true ? startDate : endDate,
      },
    }).then((res: any) => {
      gridOption5.value.setRowData(res.data.list)
      setTableTotalRow(gridOption5, res.data.list, [
        'pieceNumber',
        'bulkNumber',
        'bulkWeight',
        'weightTotal',
      ])
      tableDataList5.value = res.data.list
      fySelet4.total = res.data.total
    })
  }

  const cgHandleOk2 = async () => {
    let fly = true
    cgData2.value.forEach((item: any) => {
      if (item.bulkNumber == null) {
        item.bulkNumber = 0
      }
      if (item.bulkWeight == null) {
        item.bulkWeight = 0
      }
      if (item.weightTotal > item.weightTotal1) {
        fly = false
      }
    })
    if (fly) {
      const { code, message } = await post({
        url: 'wms/yarnTransferStock/yarnTransferOutStock',
        data: cgData2.value,
      })
      if (code == 200) {
        cxCgsList2()
        Message.success('成功')
        return true
      }
      Message.error(message)
      return false
    } else {
      Message.warning('调拨数量超出了现有总数量！')
      return false
    }
  }
  const cadelvs2 = () => {
    cgData2.value = []
    cgOut.visible2 = false
  }
  const cgData2: any = ref([])
  function changeCspn(record: any) {
    record.canStockWeight =
      parseFloat(record.planMaterialPieceWeight) * parseFloat(record.canStockPieceNum) || 0
  }
  const toFixedNum = (num: number) => {
    if(parseFloat(parseFloat(num.toFixed(2)).toFixed(2))==NaN){
      num=0
    }
    return parseFloat(num.toFixed(2))
  }
  const cahngesCount = (record: any) => {
    if (record.pieceNumber && record.bulkWeight && record.planMaterialPieceWeight != 0) {
      nextTick(() => {
        record.weightTotal = toFixedNum(
          record.pieceNumber * record.planMaterialPieceWeight + record.bulkWeight
        )
      })
    } else if (record.pieceNumber && record.planMaterialPieceWeight != 0) {
      nextTick(() => {
        record.weightTotal = toFixedNum(record.pieceNumber * record.planMaterialPieceWeight)
      })
    } else if (record.bulkWeight) {
      nextTick(() => {
        record.weightTotal = toFixedNum(record.bulkWeight)
      })
    } else {
      nextTick(() => {
        record.weightTotal = 0
      })
    }
    console.log(record)
  }
  const cahngesCount1 = (record: any) => {
    if (record.pieceNumber && record.bulkWeight && record.pieceWeight != 0) {
      nextTick(() => {
        record.weightTotal = record.pieceNumber * record.pieceWeight + record.bulkWeight
      })
    } else if (record.pieceNumber && record.pieceWeight != 0) {
      nextTick(() => {
        record.weightTotal = record.pieceNumber * record.pieceWeight
      })
    } else if (record.bulkWeight) {
      nextTick(() => {
        record.weightTotal = record.bulkWeight
      })
    } else {
      nextTick(() => {
        record.weightTotal = 0
      })
    }
  }

  const data = ref([])
  const visible = ref(false)
  const addDbFun = async () => {
    if (gridOption2.value.getSelectedRows().length == 0) {
      Message.error('请勾选')
      return false
    }
    let selectedRowKeysList: any = []
    for (let i = 0; i < gridOption2.value.getSelectedRows().length; i++) {
      selectedRowKeysList.push(gridOption2.value.getSelectedRows()[i].id)
      if (
        gridOption2.value.getSelectedRows()[0].warehouseId !=
        gridOption2.value.getSelectedRows()[i].warehouseId
      ) {
        Message.error('请勾选相同仓库')
        return
      }
      if (
        gridOption2.value.getSelectedRows()[0].company !==
        gridOption2.value.getSelectedRows()[i].company
      ) {
        Message.error('请勾选相同公司')
        return
      }
    }
    data.value = JSON.parse(
      JSON.stringify(
        tableDataList2.value.filter((o: any) => {
          return selectedRowKeysList.includes(o['id'])
        })
      )
    )
    gridOptionRef.value.setdataListIterface(data.value)
    for (let item in searchData) {
      if (item !== 'warehouseList') {
        searchData[item] = null
      }
    }
    const firstLineCompanyId = gridOption2.value.getSelectedRows()[0].companyId
    await getWarehouseList(firstLineCompanyId, '调拨单申请')
    corPor.value.parentComponent({ corporateId: gridOption2.value.getSelectedRows()[0].companyId })
    corPor.value.setcorDisabled(true)
    console.log(data.value)
    data.value.forEach((res: any) => {
      nextTick(() => {
        res['planMaterialBulkWeight'] = 0
        res['planMaterialBulkNum'] = 0
        // res['planMaterialPieceNum'] = 0
        // res['planMaterialPieceNum'] = Math.ceil(Math.abs(res['stockTotalWeight'] + res['outStockWeight'] - res['planMaterialWeight']) / res['planMaterialPieceWeight'])
        res['planMaterialPieceNum'] = res['planMaterialPieceNum'] - res['outStockPieceNum']
        res['planMaterialWeight'] = res['planMaterialPieceNum'] * res['planMaterialPieceWeight']
        // delete res.id
        // let intNumber = res['planMaterialPieceNum'] - res['pieceNumber']
        // if (intNumber <= 0) {
        //     res['planMaterialPieceNum'] = 0
        // } else {
        //     res['planMaterialPieceNum'] = intNumber
        // }
      })
    })
    visible.value = true
    searchData.orderDate = dayjs(new Date()).format('YYYY-MM-DD')
  }
  const handleWarehouseChange = (val: any) => {
    if (!val) return
    searchData.warehouseName = searchData.warehouseList.find(
      (item: any) => item.id == val
    )?.warehouseName
  }
  const pNumber2 = (e: any) => {
    nextTick(() => {
      e['planMaterialWeight'] = e['planMaterialPieceNum'] * e['planMaterialPieceWeight']
    })
  }
  const cahngesCount3 = (record: any) => {
    const data = record.value
    if (data.pieceNumber && data.pieceNumber != 0 && data.pieceWeight && data.pieceWeight != 0) {
      nextTick(() => {
        record.value.weightTotal = toFixedNum(data.pieceNumber * data.pieceWeight + data.bulkWeight)
      })
    } else {
      nextTick(() => {
        record.value.weightTotal = toFixedNum(data.bulkWeight)
      })
    }
    const listData = gridOptionRef3.value.getListData()
    nextTick(() => {
      gridOptionRef3.value.setdataListIterface(listData)
    })
  }
  const weightPieceTotalChange = (record: any) => {
    const data = record.value
    if (
      data.pieceNumber &&
      data.pieceNumber != 0 &&
      data.planMaterialPieceWeight &&
      data.planMaterialPieceWeight != 0
    ) {
      nextTick(() => {
        record.value.weightPieceTotal = toFixedNum(data.pieceNumber * data.planMaterialPieceWeight)
      })
    }
  }

  const cahngesCount4 = (record: any) => {
    const data = record.value
    if (data.pieceNumber && data.pieceNumber != 0 && data.pieceWeight && data.pieceWeight != 0) {
      nextTick(() => {
        record.value.weightTotal = toFixedNum(data.pieceNumber * data.pieceWeight + data.bulkWeight)
      })
    } else {
      nextTick(() => {
        record.value.weightTotal = toFixedNum(data.bulkWeight)
      })
    }
    const listData = gridOptionRef4.value.getListData()
    nextTick(() => {
      gridOptionRef4.value.setdataListIterface(listData)
    })
  }
  const pNumber = (e: any) => {
    nextTick(() => {
      e['planMaterialWeight'] =
        e['planMaterialPieceNum'] * e['planMaterialPieceWeight'] + e['planMaterialBulkNum']
    })
  }
  const bNumber = (e: any) => {
    nextTick(() => {
      e['planMaterialWeight'] =
        e['planMaterialPieceNum'] * e['planMaterialPieceWeight'] + e['planMaterialBulkNum']
    })
  }
  const buNumber = (e: any) => {
    nextTick(() => {
      e['planMaterialWeight'] =
        e['planMaterialPieceNum'] * e['planMaterialPieceWeight'] + e['planMaterialBulkNum']
    })
  }

  const handleOk = async () => {
    if (searchData.warehouseId == '' || searchData.warehouseId == null) {
      Message.error('仓库必选')
      return false
    }
    if (searchData.orderDate == '' || searchData.orderDate == null) {
      Message.error('开单日期必选')
      return false
    }
    const detailList = data.value.map((item: any) => {
      return {
        ...item,
        warehouseId: searchData.warehouseId,
        warehouseName: searchData.warehouseName,
      }
    })
    const res: any = await post({
      url: 'wms/yarnTransferStock/insertYarnReceipt',
      data: {
        warehouseId: searchData.warehouseId,
        orderDate: searchData.orderDate,
        remark: searchData.remark,
        detailList,
      },
    })
    if (res.code === 200) {
      cxCgsList()
      Message.success('成功')
      return true
    } else {
      Message.error(res.message)
      return false
    }
  }

  const handleCancel = () => {
    visible.value = false
  }

  const dbPageDateShowAdd = ref(false)

  const pageData2 = reactive({
    a: '',
    aId: '',
    b: '',
    bId: '',
    c: '',
    d: '',
    e: '',
    f: '',
  })

  const whService5 = new WHService()
  const shWhList5: any = whService5.whList
  const configCascader5 = ref<{}>({
    corporateWidth: '180px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: true, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const changeCascader5 = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    pageData2.b = ''
    pageData2.a = corporateLabel
    pageData2.aId = corporateId
    whService5.getWarhouseListByFirmId(corporateId, '原纱仓')
    console.log(data.corporateList)
    nextTick(() => {
      if (data.corporateList.length == 1 && !data.corporateList[0].children) {
        const fhUhlist = fhWhList.value[0]
        pageData2.b = fhUhlist.id + '-' + fhUhlist.warehouseName
      }
    })
  }

  const setcorDisabledRefs = ref()

  const addcks = () => {
    setcorDisabledRefs.value?.resetForm()
    for (let i in pageData2) {
      pageData2[i] = null
    }
    cgData3.value = []
    dbPageDateShowAdd.value = true
  }

  const formRef2: any = ref()

  const sideOk2 = () => {
    if (cgData3.value.length == 0) {
      Message.warning({
        content: '请新增至少一条原料信息',
        duration: 5000,
      })
      return
    }
    for (let i = 0; i < cgData3.value.length; i++) {
      if (
        cgData3.value[i]['transportName'] == '' ||
        cgData3.value[i]['transportName'] == undefined ||
        cgData3.value[i]['transportName'] == null
      ) {
        Message.error('搬运计件必填!')
        return false
      }
    }

    formRef2.value?.validate().then((err: any) => {
      if (!err) {
        cgData3.value.forEach((item: any) => {
          item['firm'] = pageData2.a
          item['firmId'] = pageData2.aId
          item['warehouse'] = pageData2.b.split('-')[1]
          item['warehouseId'] = Number(pageData2.b.split('-')[0])
          item['outStockType'] = pageData2.c
          item['customName'] = pageData2.d
          item['customOrderNo'] = pageData2.e
          item['totalRemark'] = pageData2.f
          delete item['id']
        })
        post({
          url: 'wms/yarnOutStock/stockOutByRerun',
          data: cgData3.value,
        }).then(({ code, message }) => {
          if (code == 200) {
            tkOutus()
            Message.success('成功')
            dbPageDateShowAdd.value = false
          } else {
            Message.error(message)
          }
        })
      }
    })
  }
  const sideNo2 = () => {
    dbPageDateShowAdd.value = false
  }

  const outStoCxList: any = ref([])

  const OutStoCx = () => {
    if (!pageData2.b) {
      Message.info('请先选择仓库')
      return
    }
    post({
      url: 'wms/stockoutType/getStockoutTypePage',
      data: {
        page: 1,
        size: 1000,
        warehouseId: Number(pageData2.b.split('-')[0]),
      },
    }).then((res: any) => {
      if (res.code == 200) {
        outStoCxList.value = res.data.list.filter((o:any)=> o.typeName != '转料虚拟出库' && o.typeName != '虚拟出库')
      }
    })
  }

  const customNameCxList: any = ref([])

  const customName = (value: any) => {
    post({
      url: 'product/Brand/getFieldValue',
      data: {
        brandName:value,
      },
    }).then((res: any) => {
      if (res.code == 200) {
        customNameCxList.value = res.data
      }
    })
  }

  const addLine2 = () => {
    isLyCodeds.value = ''
    isLyNameds.value = ''
    productionBatch.value = ''
    selectedRowKeys3.value = []
    gridOptionRef5.value.setdataListIterface([])
    wlListXqs2.value = []
    if (pageData2.b == '' || pageData2.b == undefined) {
      Message.error('请选择仓库')
      return false
    }
    if (pageData2.d == '' || pageData2.d == undefined) {
      Message.error('请选择客户')
      return false
    }
    visibleYl2.value = true
    fySelet7.total = 0
  }

  const cgData3: any = ref([])

  const delLine2 = (e: any) => {
    Modal.confirm({
      title: '系统提示',
      content: '确认删除选中的数据?',
      onOk: () => {
        cgData3.value = cgData3.value.filter((val: any) => {
          return val != e
        })
      },
    })
  }

  const isLyCodeds: any = ref('')

  const isLyNameds: any = ref('')

  const productionBatch: any = ref('')

  const selectedRowKeys3: any = ref([])

  const wlListXqs2: any = ref([])

  const cxCgsLists = async () => {
    // const res: any = await whService.wlCxMxSmWhmxWarhouse({
    //     rawmaterialCode: isLyCodeds.value,
    //     materialsName: isLyNameds.value,
    //     auditState: 1
    // })
    const res: any = await post({
      url: 'wms/yarnStock/getPage',
      data: {
        page: fySelet7.page,
        size: fySelet7.size,
        yarn_code: isLyCodeds.value,
        yarn_name: isLyNameds.value,
        production_batch: productionBatch.value,
        warehouse_id: Number(pageData2.b.split('-')[0]),
        custom_name: pageData2.d,
      },
    })
    if (res.code == 200) {
      fySelet7.total = res.data.total
      wlListXqs2.value = res.data.list
      gridOptionRef5.value.setdataListIterface(res.data.list)
    }
  }

  const visibleYl2 = ref(false)

  const handleCancels2 = () => {
    visibleYl2.value = false
  }
  const handleOks2 = () => {
    if (gridOptionRef5.value.getSelectedRows().length == 0) {
      Message.error('请勾选')
      return false
    }
    let cgData3List = gridOptionRef5.value.getSelectedRows()
    if (cgData3.value.leng != 0) {
      let yarnCodeList = []
      for (let i = 0; i < cgData3.value.length; i++) {
        yarnCodeList.push(cgData3.value[i].yarnCode)
      }
      console.log(yarnCodeList)
      for (let i = 0; i < cgData3List.length; i++) {
        if (yarnCodeList.includes(cgData3List[i].yarnCode)) {
          Message.error('请勿勾选相同原料')
          return false
        }
      }
    }
    cgData3List.forEach((item: any) => {
      item['orderType'] = 1
      item['pieceNumber2'] = item['pieceNumber']
      item['bulkCount2'] = item['bulkCount']
      item['bulkNumber2'] = item['bulkNumber']
      item['bulkWeight2'] = item['bulkWeight']
    })
    cgData3.value.push(...cgData3List)
    gridOptionRef4.value.setdataListIterface(cgData3.value)
    return true
  }

  const printList: any = ref([])
  const printList2: any = ref([])

  const dyBoufeis = () => {
    if (tabsKeys.value == 5) {
      if (gridOption6.value.getSelectedRows().length == 0) {
        Message.error('请勾选行数据！')
        return false
      }
      var paramList: any[] = []
      gridOption6.value.getSelectedRows().forEach(function (o: any) {
        if (!paramList.includes(o['outStockNumber'])) {
          paramList.push(o['outStockNumber'])
        }
      })
      printPdf(paramList, '/wms/yarnOutStock/getPrintByOutStockNumber1')
    } else if (tabsKeys.value == 1) {
      if (gridOption.value.getSelectedRows().length == 0) {
        Message.error('请勾选数据')
        return false
      }
      var paramList: any[] = []
      gridOption.value.getSelectedRows().forEach(function (o: any) {
        if (!paramList.includes(o['outStockNumber'])) {
          paramList.push(o['outStockNumber'])
        }
      })
      printPdf(paramList, '/wms/yarnOutStock/getPrintByOutStockNumber2')
    } else if (tabsKeys.value == 6) {
      if (gridOption8.value.getSelectedRows().length == 0) {
        Message.error('请勾选数据')
        return false
      }
      if (gridOption8.value.getSelectedRows().length > 1) {
        Message.error('只能勾选一条')
        return false
      }
      post({
        url: 'wms/yarnOutStock/getPrintByOutStockNumber',
        data: {
          outStockNumber: gridOption8.value.getSelectedRows()[0].outStockNumber,
        },
      }).then((res: any) => {
        if (res.code == 200) {
          printList.value = res.data
          let a = 0
          let b = 0
          let c = 0
          let d = 0
          printList.value.forEach((res: any) => {
            a += res['pieceNumber']
            b += res['bulkNumber']
            c += res['bulkWeight']
            d += res['weightTotal']
            res['pieceNumbers'] = a
            res['bulkNumbers'] = b
            res['bulkWeights'] = c
            res['weightTotals'] = d
          })
        }
      })
      visibleYl3.value = true
    }
  }

  const visibleYl3 = ref(false)
  const visibleYl4 = ref(false)

  const handleOks3 = async () => {
    await printJS({
      printable: 'wjDyings11',
      type: 'html',
      font_size: '',
      targetStyles: ['*'],
    })
    return true
  }

  const handleOks4 = async () => {
    await printJS({
      printable: 'wjDyings12',
      type: 'html',
      font_size: '',
      targetStyles: ['*'],
    })
    return true
  }

  const handleCancels3 = () => {
    visibleYl3.value = false
  }

  const handleCancels4 = () => {
    visibleYl4.value = false
  }

  const compareDate = (dateTime1: any, dateTime2: any) => {
    var formatDate1 = new Date(dateTime1)
    var formatDate2 = new Date(dateTime2)
    if (formatDate1 > formatDate2) {
      return true
    } else {
      return false
    }
  }
  const onSelect = (dateString: any, date: any) => {
    pageData.dropDownTime = {
      startDate: dateString[0],
      endDate: dateString[1],
    }
  }
  const onClear = () => {
    pageDataLl.dateList1 = []
  }
  const hzAshows: any = ref(false)
  const xqdhzs = () => {
    post({
      url: 'planSingle/planNeed/getPage',
      data: {
        page: 1,
        size: 1000000000,
        deleteState: 0,
        auditState: 0,
        disposeState: 0,
        needWeight:1,
      },
    }).then((res: any) => {
      hzDataList.value = res.data.list
      hzAshows.value = true
    })
  }
  const hzSOks = async () => {
    if (gridOptionhz.value.getSelectedRows().length == 0) {
      Message.error('请勾选')
      return
    }
    const res: any = await post({
      url: 'planSingle/planMaterial/savePartOrder',
      data: {
        needIds: gridOptionhz.value.getSelectedRows().map((ids: any) => {
          return ids.id
        }),
      },
    })
    if (res.code === 200) {
      fySeletLl.page = 1
      doRefreshsLl()
      hzAshows.value = false
      Message.success('汇总成功')
    } else {
      Message.error(res.message)
    }
    // fhWhListhz.value = []
    // searchDatahz.warehouseId = null
    // searchDatahz.firmId = null
    // visiblehz.value = true
    // corPorhz.value.resetForm()
  }
  const gridOptionhz = ref()
  const gridReadyhz = (params: any) => {
    gridOptionhz.value = params.api
  }

  const hzDataList: any = ref([])

  const tableColumns1: any = [
    {
      title: '单号',
      key: 'planNeedCode',
      dataIndex: 'planNeedCode',
      width: 150,
    },
    {
      title: '织布单号',
      key: 'planOrderCode',
      dataIndex: 'planOrderCode',
      width: 150,
    },
    {
      title: '客户名称',
      key: 'customName',
      dataIndex: 'customName',
      width: 150,
    },
    {
      title: '原料编号',
      key: 'rawmaterialCode',
      dataIndex: 'rawmaterialCode',
      width: 150,
    },
    {
      title: '原料名称',
      key: 'rawmaterialName',
      dataIndex: 'rawmaterialName',
      width: 200,
    },
    {
      title: '机台号',
      key: 'machineCode',
      dataIndex: 'machineCode',
      width: 150,
    },
    {
      title: '排产日期',
      key: 'schedulDate',
      dataIndex: 'schedulDate',
      width: 150,
    },
    {
      title: '重量',
      key: 'needWeight',
      dataIndex: 'needWeight',
      width: 150,
    },
    {
      title: '件数',
      key: 'needPieceNum',
      dataIndex: 'needPieceNum',
      width: 150,
    },
    {
      title: '需求人',
      key: 'needPerson',
      dataIndex: 'needPerson',
      width: 150,
    },
    {
      title: '生产单号',
      key: 'weavingCode',
      dataIndex: 'weavingCode',
      width: 150,
    },
    {
      title: '纱牌',
      key: 'brandName',
      dataIndex: 'brandName',
      width: 150,
    },
    {
      title: '单位',
      key: 'unit',
      dataIndex: 'unit',
      width: 150,
    },
    {
      title: '色号',
      key: 'colorCode',
      dataIndex: 'colorCode',
      width: 150,
    },
    {
      title: '色称',
      key: 'colorName',
      dataIndex: 'colorName',
      width: 150,
    },
    {
      title: '备注',
      key: 'remark',
      dataIndex: 'remark',
      width: 150,
    },
    {
      title: '加急件数',
      key: 'urgentCount',
      dataIndex: 'urgentCount',
      width: 150,
    },
    {
      title: '创建人',
      key: 'createName',
      dataIndex: 'createName',
      width: 150,
    },
    {
      title: '创建时间',
      key: 'createTime',
      dataIndex: 'createTime',
      width: 180,
    },
  ]
  let tchz: any[] = tableColumns1.map((o: any) => {
    let obj = {
      headerName: o.title,
      field: o.key,
      pinned: o['fixed'],
    }
    return obj
  })

  let ahz = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
  ]
  tchz = ahz.concat(tchz)

  const visiblehz: any = ref(false)

  const searchDatahz: any = reactive({
    warehouseId: null,
    firmId: null,
  })
  const whServicehz = new WHService()
  const fhWhListhz: any = whServicehz.whList
  const changeCascaderhz = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    searchDatahz.warehouseId = ''
    searchDatahz.firmId = corporateId
    whServicehz.getWarhouseListByFirmId(corporateId, '原纱仓')
  }
  const configCascaderhz = ref<{}>({
    corporateWidth: '15rem', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: true, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '发货公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const chuangjianlinliaodanshz = () => {
    visiblehz.value = true
  }

  const formRefhz: any = ref()
  const corPorhz: any = ref()
  const handleOkhz = async () => {
    const err = await formRefhz.value.validate()
    if (!err) {
      const res: any = await post({
        url: 'planSingle/planMaterial/savePartOrder',
        data: {
          warehouseId: searchDatahz.warehouseId,
          needIds: gridOptionhz.value.getSelectedRows().map((ids: any) => {
            return ids.id
          }),
        },
      })
      if (res.code === 200) {
        fySelet.page = 1
        cxCgsList()
        visiblehz.value = false
        Message.success('汇总成功')
        return true
      } else {
        Message.error(res.message)
        return false
      }
    }
  }

  const pageDataLl: any = reactive({
    dropDownDataqszs: {
      startDate: '',
      endDate: '',
    },
    lingliaodanhao: null,
    yuanliaobianhao: '',
    yuanliaomingc: '',
    kname: '',
    dateList: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')],
    dateList1: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')],
    auditState: 0,
  })

  const onSelectLl = (dateString: any, date: any) => {
    pageDataLl.dropDownTime = {
      startDate: dateString[0],
      endDate: dateString[1],
    }
  }
  const onClearLl = () => {
    pageDataLl.dateList = []
  }

  const tableColumns2Lls: any = ref([
    {
      title: '公司名称',
      key: 'company',
      dataIndex: 'company',
      width: 150,
    },
    {
      title: '领料单号',
      key: 'planMaterialCode',
      dataIndex: 'planMaterialCode',
      width: 150,
    },
    {
      title: '客户名称',
      key: 'customName',
      dataIndex: 'customName',
      width: 150,
    },
    {
      title: '开单日期',
      key: 'createTime',
      dataIndex: 'createTime',
      width: 200,
    },
    // {
    //     title: "计划单号",
    //     key: "planOrderCode",
    //     dataIndex: "planOrderCode",
    //     width: 150,
    // },
    // {
    //     title: "机台号",
    //     key: "machineCode",
    //     dataIndex: "machineCode",
    //     width: 150,
    // },
    {
      title: '原料编号',
      key: 'rawMaterialCode',
      dataIndex: 'rawMaterialCode',
      width: 150,
    },
    {
      title: '原料名称',
      key: 'rawMaterialName',
      dataIndex: 'rawMaterialName',
      width: 150,
    },
    {
      title: '纱牌',
      key: 'brandName',
      dataIndex: 'brandName',
      width: 150,
    },
    {
      title: '纱批',
      key: 'yarnBatch',
      dataIndex: 'yarnBatch',
      width: 150,
    },
    {
      title: '色号',
      key: 'colorCode',
      dataIndex: 'colorCode',
      width: 150,
    },
    {
      title: '色称',
      key: 'colorName',
      dataIndex: 'colorName',
      width: 150,
    },
    {
      title: '可配色称',
      key: 'matchColor',
      dataIndex: 'matchColor',
      width: 150,
    },
    {
      title: '整件/个数',
      key: 'pieceCount',
      dataIndex: 'pieceCount',
      width: 150,
    },
    {
      title: '领料-整件/件数',
      key: 'planMaterialPieceNum',
      dataIndex: 'planMaterialPieceNum',
      width: 150,
    },
    {
      title: '领料-整件/件重',
      key: 'planMaterialPieceWeight',
      dataIndex: 'planMaterialPieceWeight',
      width: 150,
    },
    {
      title: '领料-总重量',
      key: 'planMaterialWeight',
      dataIndex: 'planMaterialWeight',
      width: 150,
      fixed: 'right',
    },
    {
      title: '单位',
      key: 'unit',
      dataIndex: 'unit',
      width: 150,
    },
    {
      title: '等级',
      key: 'level',
      dataIndex: 'level',
      width: 150,
    },
    {
      title: '加急件数',
      key: 'urgentCount',
      dataIndex: 'urgentCount',
      width: 150,
    },
    {
      title: '库存-整件/件数',
      key: 'pieceNumber',
      dataIndex: 'pieceNumber',
      width: 150,
    },
    {
      title: '库存-整件/件重',
      key: 'pieceWeight',
      dataIndex: 'pieceWeight',
      width: 150,
    },
    {
      title: '库存-散件/件数',
      key: 'bulkNumber',
      dataIndex: 'bulkNumber',
      width: 150,
    },
    {
      title: '库存-散件/散重',
      key: 'bulkWeight',
      dataIndex: 'bulkWeight',
      width: 150,
    },
    {
      title: '库存-总数量',
      key: 'weightTotal',
      dataIndex: 'weightTotal',
      width: 150,
    },
    {
      title: '审核状态',
      key: 'auditState',
      dataIndex: 'auditState',
      slotName: 'auditState',
      width: 150,
      fixed: 'right',
    },
    {
      title: '是否加急',
      key: 'urgentState',
      dataIndex: 'urgentState',
      slotName: 'urgentState',
      width: 120,
      fixed: 'right',
    },
  ])
  let tcLls: any[] = tableColumns2Lls.value.map((o: any) => {
    let obj = {
      headerName: o.title,
      field: o.key,
      pinned: o['fixed'],
    }
    if (o.key === 'auditState') {
      obj['resizable'] = false
      obj['sortable'] = false
      obj['lockPosition'] = 'right'
      obj['width'] = 120
      obj['cellRenderer'] = {
        template: `
        <el-tag v-if="b == 4" type="success">已&nbsp;&nbsp;拆&nbsp;&nbsp;纱</el-tag>
                    <el-tag v-if="b == 3" type="success">已&nbsp;&nbsp;领&nbsp;&nbsp;料</el-tag>
                    <el-tag v-if="b == 2" type="danger">&nbsp;&nbsp;驳&nbsp;&nbsp;&nbsp;&nbsp;回&nbsp;&nbsp;</el-tag>
                    <el-tag v-if="b == 1" type="success">审核通过</el-tag>
                    <el-tag v-if="b == 0" type="warning">未&nbsp;&nbsp;审&nbsp;&nbsp;核</el-tag>
        `,
        setup(props: any) {
          return {
            b: props.params.data.auditState,
          }
        },
      }
      obj['cellStyle'] = (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      }
      obj['filterParams'] = {
        valueFormatter: (params: any) => {
          let str
          switch (params.value) {
            case 0:
              str = '未审核'
              break
            case 1:
              str = '审核通过'
              break
            case 2:
              str = '驳回'
              break
            case 3:
              str = '已领料'
              break
            case 4:
              str = '已拆纱'
              break
            default:
              str = params.value
              break
          }
          return str
        },
      }

      // filterParams: {
      //               valueFormatter: (params) => {
      //                   return params.value == 0 ? '未删除' : '已删除'
      //               },
      //           },
    }
    if (o.key == 'planState') {
      obj['resizable'] = false
      obj['filter'] = false
      obj['sortable'] = false
      obj['cellRenderer'] = {
        template: ` <span v-if="b == 0">自行生产</span>`,
        setup(props: any) {
          return {
            b: props.params.data.planState,
          }
        },
      }
      obj['cellStyle'] = (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      }
    }
    if (o.key == 'planMaterialWeight') {
      obj['resizable'] = false
      obj['filter'] = false
      obj['sortable'] = false
      obj['lockPosition'] = 'right'
      obj['width'] = 120
      obj['cellRenderer'] = {
        template: `
      <a-popover title="需求单明细" v-if="d.rowPinned!='bottom'">
              <a-button :style="{ width: '100px' }" type="outline">{{b}}</a-button>
              <template #content>
                <a-table :columns="columns" :data="c" :pagination="false" style="max-height:40vh;overflow-y:auto;"/>
              </template>
           </a-popover>
           <div style="border-left: 1px solid #babfc7;" v-else>{{b}}</div>
            `,
        setup(props: any) {
          const columns = ref([
            {
              title: '需求单号',
              key: 'planNeedCode',
              dataIndex: 'planNeedCode',
              width: 180,
            },
            {
              title: '织布单号',
              key: 'planOrderCode',
              dataIndex: 'planOrderCode',
              width: 180,
            },
            {
              title: '机台号',
              key: 'machineCode',
              dataIndex: 'machineCode',
              width: 100,
            },
            {
              title: '需求数量',
              key: 'needPieceNum',
              dataIndex: 'needPieceNum',
              width: 100,
            },
            {
              title: '需求重量',
              key: 'needWeight',
              dataIndex: 'needWeight',
              width: 100,
            },
            {
              title: '备注',
              key: 'remark',
              dataIndex: 'remark',
              width: 100,
            },
          ])
          return {
            columns,
            b: props.params.data.planMaterialWeight,
            c: props.params.data.needInfoList,
            d: props.params.node,
          }
        },
      }
    }
    if (o.key == 'urgentState') {
      obj['resizable'] = false
      obj['sortable'] = false
      obj['width'] = 120
      obj['cellRenderer'] = {
        template: `
            <a-button v-if="b == 0" status="success" size="mini">正常</a-button>
            <a-button v-if="b == 1" type="primary" status="danger" size="mini">加急</a-button>
            `,
        setup(props: any) {
          return {
            b: props.params.data.urgentState,
          }
        },
      }
      obj['cellStyle'] = (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      }
      obj['filterParams'] = {
        valueFormatter: function (params: any) {
          return params.value == '0' ? '正常' : params.value == '1' ? '加急' : ''
        },
      }
    }
    return obj
  })

  let aLls = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
  ]
  tcLls = aLls.concat(tcLls)

  const gridOptionLls = ref()
  const colState2 = ref()
  const gridReadyLls = (params: any) => {
    gridOptionLls.value = params.api
    colState2.value = params.columnApi
  }

  const LlDataList: any = ref([])

  const fySeletLl: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSizeLl = (val: any) => {
    fySeletLl.page = val
    doRefreshsLl()
  }

  const changeLl = (val: any) => {
    fySeletLl.size = val
    doRefreshsLl()
  }

  const selectCx = () => {
    fySeletLl.page = 1
    doRefreshsLl()
  }

  async function doRefreshsLl() {
    if (pageDataLl.dateList.length != 0) {
      var startDate = pageDataLl.dateList[0]
      var endDate = pageDataLl.dateList[1]
      let data1 = startDate
      let data2 = endDate
      var formatDate1 = new Date(startDate)
      var formatDate2 = new Date(endDate)
      if (formatDate1 > formatDate2) {
        startDate = data2 ? data2 + ' 00:00:00' : ''
        endDate = data1 ? data1 + ' 23:59:59' : ''
      } else {
        startDate = data1 ? data1 + ' 00:00:00' : ''
        endDate = data2 ? data2 + ' 23:59:59' : ''
      }
    } else {
      ;(startDate = ''), (endDate = '')
    }
    const res = await post({
      url: 'planSingle/planMaterial/getPage',
      data: {
        page: fySeletLl.page,
        size: fySeletLl.size,
        deleteState: 0,
        startDate: startDate,
        endDate: endDate,
        planOrderCode: pageDataLl.lingliaodanhao,
        rawMaterialCode: pageDataLl.yuanliaobianhao,
        rawMaterialName: pageDataLl.yuanliaomingc,
        customName: pageDataLl.kname,
        planMaterialCode: pageDataLl.lingliaodanhao,
        auditState: pageDataLl.auditState === '' ? undefined : pageDataLl.auditState,
      },
    })
    if (res.code == 200) {
      LlDataList.value = res.data.list
      setTableTotalRow(gridOptionLls, res.data.list, [
        'urgentCount',
        'pieceNumber',
        'bulkNumber',
        'bulkWeight',
        'weightTotal',
        'planMaterialWeight',
      ])
      fySeletLl.total = res.data.total
    }
  }
  const dataLlDb: any = ref([])
  const visibleLlDb = ref(false)
  const addDbFuns = () => {
    if (gridOptionLls.value.getSelectedRows().length == 0) {
      Message.error('请勾选数据')
      return false
    }
    dataLlDb.value = gridOptionLls.value.getSelectedRows()
    for (let rowIndex = 0; rowIndex < dataLlDb.value.length - 1; rowIndex++) {
      if (dataLlDb.value[rowIndex].warehouseId != dataLlDb.value[rowIndex + 1].warehouseId) {
        Message.error('请勾选相同仓库')
        return false
      }
    }
    for (let item in searchDataLldb) {
      if (item == 'orderDate') {
        searchDataLldb[item] = dayjs().format('YYYY-MM-DD')
      } else {
        searchDataLldb[item] = null
      }
    }
    dataLlDb.value.forEach((res: any) => {
      nextTick(() => {
        res['planMaterialBulkWeight'] = 0
        res['planMaterialBulkNum'] = 0
        let intNumber = res['planMaterialPieceNum'] - res['pieceNumber']
        if (intNumber <= 0) {
          res['planMaterialPieceNum'] = 0
        } else {
          res['planMaterialPieceNum'] = intNumber
        }
      })
    })
    visibleLlDb.value = true
  }
  const searchDataLldb: any = reactive({
    warehouseId: null,
    firmId: null,
    orderDate: null,
    remark: null,
  })

  const tableColumnsLlDb: any = ref([
    {
      title: '客户名称',
      key: 'customName',
      dataIndex: 'customName',
      width: 150,
    },
    {
      title: '原料编号',
      key: 'rawMaterialCode',
      dataIndex: 'rawMaterialCode',
      width: 150,
    },
    {
      title: '原料名称',
      key: 'rawMaterialName',
      dataIndex: 'rawMaterialName',
      width: 150,
    },
    {
      title: '纱牌',
      key: 'brandName',
      dataIndex: 'brandName',
      width: 150,
    },
    {
      title: '纱批',
      key: 'yarnBatch',
      dataIndex: 'yarnBatch',
      width: 150,
    },
    {
      title: '色号',
      key: 'colorCode',
      dataIndex: 'colorCode',
      width: 150,
    },
    {
      title: '色称',
      key: 'colorName',
      dataIndex: 'colorName',
      width: 150,
    },
    {
      title: '可配色称',
      key: 'matchColor',
      dataIndex: 'matchColor',
      width: 150,
    },
    {
      title: '等级',
      key: 'level',
      dataIndex: 'level',
      width: 150,
    },
    {
      title: '领料整件件数',
      key: 'planMaterialPieceNum',
      dataIndex: 'planMaterialPieceNum',
      slotName: 'planMaterialPieceNum',
      width: 150,
    },
    {
      title: '整件/件重',
      key: 'planMaterialPieceWeight',
      dataIndex: 'planMaterialPieceWeight',
      width: 150,
    },
    {
      title: '领料散件件数',
      key: 'planMaterialBulkWeight',
      dataIndex: 'planMaterialBulkWeight',
      slotName: 'planMaterialBulkWeight',
      width: 150,
    },
    {
      title: '领料散件件重',
      key: 'planMaterialBulkNum',
      dataIndex: 'planMaterialBulkNum',
      slotName: 'planMaterialBulkNum',
      width: 150,
    },
    {
      title: '领料-总重量',
      key: 'planMaterialWeight',
      dataIndex: 'planMaterialWeight',
      width: 150,
    },
    {
      title: '单位',
      key: 'unit',
      dataIndex: 'unit',
      width: 150,
    },
    {
      title: '备注',
      key: 'remark',
      dataIndex: 'remark',
      slotName: 'remark',
      width: 150,
    },
  ])

  const configCascaderLlDb = ref<{}>({
    corporateWidth: '15rem', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: true, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '申请公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const whServiceLlDb = new WHService()
  const fhWhListLlDb: any = whServiceLlDb.whList
  const changeCascaderLlDb = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    searchDataLldb.warehouseId = ''
    searchDataLldb.firmId = corporateId
    whServiceLlDb.getWarhouseListByFirmId(corporateId, '原纱仓')
  }

  const pNumberLlDb = (e: any) => {
    nextTick(() => {
      e['planMaterialWeight'] =
        e['planMaterialPieceNum'] * e['planMaterialPieceWeight'] + e['planMaterialBulkNum']
    })
  }
  const bNumberLlDb = (e: any) => {
    nextTick(() => {
      e['planMaterialWeight'] =
        e['planMaterialPieceNum'] * e['planMaterialPieceWeight'] + e['planMaterialBulkNum']
    })
  }
  const buNumberLlDb = (e: any) => {
    nextTick(() => {
      e['planMaterialWeight'] =
        e['planMaterialPieceNum'] * e['planMaterialPieceWeight'] + e['planMaterialBulkNum']
    })
  }

  const handleOkLlDb = async () => {
    if (searchDataLldb.warehouseId == '' || searchDataLldb.warehouseId == null) {
      Message.error('仓库必选')
      return false
    }
    if (searchDataLldb.orderDate == '' || searchDataLldb.orderDate == null) {
      Message.error('仓库必选')
      return false
    }
    const res: any = await post({
      url: 'wms/yarnTransferStock/insertYarnReceipt',
      data: {
        warehouseId: searchDataLldb.warehouseId,
        orderDate: searchDataLldb.orderDate,
        remark: searchDataLldb.remark,
        detailList: dataLlDb.value,
      },
    })
    if (res.code === 200) {
      doRefreshsLl()
      Message.success('成功')
      return true
    } else {
      Message.error(res.message)
      return false
    }
  }
  const handleCancelLlDb = () => {
    visible.value = false
    corporLlDb.value.resetForm()
  }
  const auditsLlDb = () => {
    if (gridOptionLls.value.getSelectedRows().length == 0) {
      Message.error('请勾选数据')
      return false
    }
    Modal.confirm({
      title: '系统提示',
      content: '是否审核此订单',
      onOk() {
        post({
          url: 'planSingle/planMaterial/audit',
          data: gridOptionLls.value.getSelectedRows().map((x: any) => {
            return { id: x.id, auditState: 1 }
          }),
        }).then((res: any) => {
          if (res.code === 200) {
            doRefreshsLl()
            Message.success('审核通过')
          } else {
            Message.error(res.message)
          }
        })
      },
    })
  }

  const countersLlDb = () => {
    if (gridOptionLls.value.getSelectedRows().length == 0) {
      Message.error('请勾选数据')
      return false
    }
    for (let i = 0; i < gridOptionLls.value.getSelectedRows().length; i++) {
      if (
        gridOptionLls.value.getSelectedRows()[i].outStockPieceNum > 0 ||
        gridOptionLls.value.getSelectedRows()[i].outStockWeight > 0
      ) {
        Message.error('订单已出库')
        return false
        break
      }
    }
    Modal.confirm({
      title: '系统提示',
      content: '是否反审订单',
      onOk() {
        post({
          url: 'planSingle/planMaterial/audit',
          // data: auditStateId,
          data: gridOptionLls.value.getSelectedRows().map((x: any) => {
            return { id: x.id, auditState: 0 }
          }),
        }).then((res: any) => {
          if (res.code === 200) {
            doRefreshsLl()
            Message.success('订单已反审')
          } else {
            Message.error(res.message)
          }
        })
      },
    })
  }

  const rejectedsLlDb = () => {
    if (gridOptionLls.value.getSelectedRows().length == 0) {
      Message.error('请勾选数据')
      return false
    }
    Modal.confirm({
      title: '系统提示',
      content: '是否驳回订单',
      onOk() {
        post({
          url: 'planSingle/planMaterial/audit',
          // data: auditStateId,
          data: gridOptionLls.value.getSelectedRows().map((x: any) => {
            return { id: x.id, auditState: 2 }
          }),
        }).then((res: any) => {
          if (res.code === 200) {
            doRefreshsLl()
            Message.success('订单已驳回')
          } else {
            Message.error(res.message)
          }
        })
      },
    })
  }

  const delsLlDb = () => {
    if (gridOptionLls.value.getSelectedRows().length == 0) {
      Message.error('请勾选数据')
      return false
    }
    Modal.confirm({
      title: '系统提示',
      content: '是否删除订单',
      onOk() {
        post({
          url: 'planSingle/planMaterial/delete',
          data: gridOptionLls.value.getSelectedRows().map((x: any) => {
            return x.id
          }),
        }).then((res: any) => {
          if (res.code === 200) {
            doRefreshsLl()
            Message.success(res.message)
          } else {
            Message.error(res.message)
          }
        })
      },
    })
  }
  //打印预览PDF
  const printPdf = (e: any, path: any) => {
    post({
      url: path,
      data: e,
      responseType: 'blob',
    }).then((res: any) => {
      let reader: any = new FileReader()
      reader.readAsDataURL(res)
      reader.onload = function () {
        let pdfBase64 = reader.result.replace('data:application/pdf;base64,', '')
        printJS({ printable: pdfBase64, type: 'pdf', base64: true })
      }
    })
  }

  //搬运计件下拉框
  function focusTransportName() {
    get({
      url: 'pieceData/transportPrice/selectTransportRefund',
      data: {},
    }).then((res: any) => {
      if (res.code == 200) {
        pageData.transportNameList = res.data.list
      } else {
        Message.error(res.message)
      }
    })
  }
  const { saveGridState: saveGridState01, updateGridState: updateGridState01 } =
    saveOrUpdateGridState01('OrderDeliveryList3-1', gridOption, colState, tc)
  const onColumnMoved = () => {
    saveGridState01()
  }
  const onColumnResized = () => {
    saveGridState01()
  }
  const onColumnVisible = () => {
    saveGridState01()
  }
  const { saveGridState: saveGridState02, updateGridState: updateGridState02 } =
    saveOrUpdateGridState02('OrderDeliveryList3-2', gridOptionLls, colState2, tcLls)
  const onColumnMoved2 = () => {
    saveGridState02()
  }
  const onColumnResized2 = () => {
    saveGridState02()
  }
  const onColumnVisible2 = () => {
    saveGridState02()
  }
  const { saveGridState: saveGridState03, updateGridState: updateGridState03 } =
    saveOrUpdateGridState03('OrderDeliveryList3-3', gridOption2, colState3, tc2)
  const onColumnMoved3 = () => {
    saveGridState03()
  }
  const onColumnResized3 = () => {
    saveGridState03()
  }
  const onColumnVisible3 = () => {
    saveGridState03()
  }
  const { saveGridState: saveGridState04, updateGridState: updateGridState04 } =
    saveOrUpdateGridState04('OrderDeliveryList3-4', gridOption3, colState4, tc3)
  const onColumnMoved4 = () => {
    saveGridState04()
  }
  const onColumnResized4 = () => {
    saveGridState04()
  }
  const onColumnVisible4 = () => {
    saveGridState04()
  }
  const { saveGridState: saveGridState05, updateGridState: updateGridState05 } =
    saveOrUpdateGridState05('OrderDeliveryList3-5', gridOption5, colState5, tc3)
  const onColumnMoved5 = () => {
    saveGridState05()
  }
  const onColumnResized5 = () => {
    saveGridState05()
  }
  const onColumnVisible5 = () => {
    saveGridState05()
  }
  const { saveGridState: saveGridState06, updateGridState: updateGridState06 } =
    saveOrUpdateGridState06('OrderDeliveryList3-6', gridOption6, colState6, tc6)
  const onColumnMoved6 = () => {
    saveGridState06()
  }
  const onColumnResized6 = () => {
    saveGridState06()
  }
  const onColumnVisible6 = () => {
    saveGridState06()
  }
  const { saveGridState: saveGridState07, updateGridState: updateGridState07 } =
    saveOrUpdateGridState07('OrderDeliveryList3-7', gridOption8, colState8, tc7)
  const onColumnMoved7 = () => {
    saveGridState07()
  }
  const onColumnResized7 = () => {
    saveGridState07()
  }
  const onColumnVisible7 = () => {
    saveGridState07()
  }

  const theEnds = () => {
    if (gridOption2.value.getSelectedRows().length === 0) {
      Message.error('请勾选需要完结的数据!')
      return
    }
    let hasWJ = gridOption2.value.getSelectedRows().some(function (obj: any) {
      return obj.useState === 1
    })
    if (hasWJ) {
      Message.error('勾选中包含已完结数据！不可完结！')
      return
    }
    Modal.confirm({
      title: '系统提示',
      content: '是否完结领料单',
      async onOk() {
        try {
          const res = await post({
            url: '/planSingle/planMaterial/updateState',
            data: gridOption2.value.getSelectedRows().map((res: any) => res.id),
          })
          if (res.code === 200) {
            Message.success('完结成功!')
            fySelet.page = 1
            cxCgsList()
          } else {
            Message.error(res.message)
          }
        } catch (error) {
          console.log(error)
        }
      },
    })
  }
  //取消审核
  const cancelAudit = () => {
    if (tabsKeys.value == 4) {
      if (gridOption5.value.getSelectedRows().length == 0) {
        Message.error('请选择需要取消审核的数据')
        return
      }
      Modal.confirm({
        title: '提示',
        content: '是否确认取消审核',
        onOk: async () => {
          const ids = gridOption5.value.getSelectedRows().map((item: any) => {
            return item.id
          })
          const res = await post({
            url: 'wms/yarnTransferStock/canceYarnTransferOutStock',
            data: ids,
          })
          try {
            if (res.code == 200) {
              Message.success('取消审核成功')
              cxCgsList3()
            } else {
              Message.error(res.message)
            }
          } catch (e) {
            console.log(e)
          }
        },
      })
    }
  }
  const drawerData = reactive<any>({
    warehouseTypeId: '',
    warehouseList: [],
    company: '',
    companyId: '',
  })
  const getWarehouseList = async (firmId: any, type: string) => {
    try {
      const params = {
        firmId,
        virtuallyState: 0,
        warehouseTypeName: '原纱仓',
      }
      const res = await post({
        url: 'wms/warehouse/getWarehouseByPara',
        data: params,
      })
      if (res.code == 200) {
        if (type === '出库') {
          drawerData.warehouseList = res.data
          if (res.data.length > 0) {
            drawerData.warehouseTypeId = res.data[0].id
          }
        }
        if (type === '调拨单申请') {
          searchData.warehouseList = res.data
          if (res.data.length == 1) {
            searchData.warehouseId = res.data[0].id
            searchData.warehouseName = res.data[0].warehouseName
          }
        }
      } else {
        Message.error(res.message)
      }
    } catch (error) {
      console.log(error)
    }
  }

const whChange = async () =>{
  await getOutStock()
  if(pageData.outStockList.length > 0){
    pageData.outStockTypes = pageData.outStockList.filter((o:any)=> o != '转料虚拟出库' && o != '虚拟出库')
  }
}
  //入库类型下拉
  const getOutStock  = async () =>{
    const res = await post({
        url: 'wms/stockoutType/getStockoutTypePage',
        data: {
          page: 1, 
          size: 1000, 
          firmId: pageData.a, 
          warehouseId: pageData.b
        },
      })
      if (res.code == 200) {
        let list = []
          for (let i = 0; i < res.data.list.length; i++) {
            var ob = res.data.list[i].typeName
            list.push(ob)
          }
          const arr = list
          const setData = Array.from(new Set(arr));
          pageData.outStockList = setData
      } else {
        Message.error(res.message)
      }
  }
</script>

<style scoped lang="less">
  :deep(.ag-cell-value) {
    user-select: initial;
    -moz-user-select: text;
    -ms-user-select: text;
    -webkit-user-select: text;
  }

  :deep(.arco-table-td-content) {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  :deep(.ag-cell) {
    border-right: 1px solid #dde2eb;
  }

  :deep(.ag-header-cell) {
    border-right: 1px solid #dde2eb;
  }

  .isTable {
    width: 100%;
    height: 70%;
    margin: 0 auto;
    border: 1.2px solid #000;
    text-align: center;
    border-collapse: collapse;

    tr {
      height: 10px;
    }

    td {
      border: 1.2px solid #000;
    }

    th {
      border: 1.2px solid #000;
    }
  }

  .No1 {
    width: 100%;
    height: 30%;
    margin-bottom: 10px;

    .No1-1 {
      width: 100%;
      font-size: 20px;
      font-weight: 550;
      text-align: center;
    }

    .No1-2 {
      width: 100%;
      font-size: 20px;
      font-weight: 500;
      text-align: center;
    }

    .No1-4 {
      width: 72%;
      display: flex;
      justify-content: space-between;
    }

    .No1-4-1 {
      width: 100%;
      display: flex;
      justify-content: space-between;
    }

    .No1-5 {
      width: 100%;
    }
  }

  .No1-3 {
    margin-top: 10px;
    width: 72%;
    display: flex;
    justify-content: space-between;
  }

  :deep(.arco-picker input) {
    padding-left: 0 !important;
  }

  :deep(.arco-picker) {
    padding-left: 0 !important;
  }

  :deep(.arco-picker-separator) {
    padding: 0 !important;
  }
  :deep(.arco-modal-body) {
    overflow-y: hidden !important;
  }
</style>
